0

I have a WebJob that works fine with a FileTrigger pointing to a specific directory but I would like to monitor files added to all directories underneath it:

data
  |_ dir one (file added here)
  |_ dir two (file added here)

I currently have the trigger set up as:

[FileTrigger(@"data\{name}", "*", WatcherChangeTypes.Created, autoDelete: true)] string message,

I can only add one trigger (which makes absolute sense) and the following doesn't work either:

@"data\*\{name}"

What will be the best way to monitor those directories from a single WebJob?

onesixtyfourth
  • 744
  • 9
  • 30
  • Looking at the FileTrigger code https://github.com/Azure/azure-webjobs-sdk-extensions/blob/dev/src/WebJobs.Extensions/Extensions/Files/Listener/FileListener.cs I don't see a way to set IncludeSubdirectories https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.includesubdirectories(v=vs.110).aspx to true in the FileSystemWatcher. So perhaps you can open a pull request about this in the GitHub repository. – andresm53 Jul 04 '18 at 14:41
  • Actually I am going to attempt to add separate functions to look at each directory so I need to know how to have "data\%app setting value%\{name}" as the trigger path. – onesixtyfourth Jul 04 '18 at 14:55

1 Answers1

1

Actually I am going to attempt to add separate functions to look at each directory so I need to know how to have "data\%app setting value%{name}" as the trigger path.

It seems that you could not use data\%app setting value%\{name} as the trigger path.

Because when you run webjobs, It will get the file path like c:\temp\files\clients\%foldername%,it will show the path does not exist. Error message as below: enter image description here

So, I suggest that you could add separate functions in the same webjobs to look at each directory like:

public void TriggerTest([FileTrigger(@"data\dirone\{name}", "*", WatcherChangeTypes.Created)] Stream file, string name, TextWriter log)

When Webjobs runs, it will find all the functions in it and then job host start.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Yes that is where I have been but that approach does not resolve the issue as I still need to have different values as we deploy through different environments. We have separate structures for each "so called" environment. If thats not clear what I mean is that I need to be able to resolve part of the path at runtime. :( – onesixtyfourth Jul 05 '18 at 13:50
  • I am going to accept this answer as it is spot on and what I have had to do. Can I request that resolving is added to the FileTrigger somewhere? – onesixtyfourth Jul 06 '18 at 10:32
  • I am not clear about what the resolving you meant, for more details you could refer to the [webjob sdk extension](https://github.com/Azure/azure-webjobs-sdk-extensions). – Joey Cai Jul 09 '18 at 01:47
  • By resolving I mean that I am able to place the same "%%" in the FileTrigger annotation Which is currently not supported. How would I go about lodging a request like that? – onesixtyfourth Jul 09 '18 at 07:19
  • You could go to feedback at this [link](https://feedback.azure.com/forums/34192--general-feedback). – Joey Cai Jul 09 '18 at 07:28
  • thanks I have done that https://feedback.azure.com/forums/34192--general-feedback/suggestions/34780528-allow-patterns-in-filetrigger-bindings – onesixtyfourth Jul 09 '18 at 09:19