Reputation: 827
I've created a WebJob to read files from Azure Files when they are created. When I run it locally it works but it doesn't when I publish the WebJob.
My Main() function is:
static void Main()
{
string connection = "DefaultEndpointsProtocol=https;AccountName=MYACCOUNTNAME;AccountKey=MYACCOUNTKEY";
JobHostConfiguration config = new JobHostConfiguration(connection);
var filesConfig = new FilesConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
filesConfig.RootPath = @"c:\temp\files";
}
config.UseFiles(filesConfig);
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
The function to be triggered when the file is created is:
public void TriggerTest([FileTrigger(@"clients\{name}", "*.txt", WatcherChangeTypes.Created)] Stream file, string name, TextWriter log)
{
log.WriteLine(name + " received!");
// ...
}
And the error I get when the WebJob is published is:
[08/17/2016 00:15:31 > 4df213: ERR ] Unhandled Exception: System.InvalidOperationException: Path 'D:\home\data\clients' does not exist.
The ideia is to make the WebJob to trigger when new files are created in the "clients" folder of the Azure Files.
Can someone help me?
Upvotes: 4
Views: 1906
Reputation: 2787
In Azure Environment, the "Web-Jobs" are stored in its local folder where known as "D:\home" and "D:\local" is the local folder used by the Web-hooks. I was in need to use a folder for temporary usage of downloading a file from SFTP server and again read the file from that local temporary location file and consume it in my application.
I have used the "D:\local\Temp" as the temporary folder which is created by the code after checking the folder existence, then after creating the folder the code will download a file from server and store to this location and then read from the same location and delete the file from that temporary folder.
Upvotes: 0
Reputation: 3293
According to your requirement, I tested it on my side, then I reproduced your issue.
Unhandled Exception: System.InvalidOperationException: Path 'D:\home\data\clients' does not exist
When publish the WebJob, the FilesConfiguration.RootPath would be set to the “D:\HOME\DATA” directory when running in Azure Web App. You could refer to the source code: https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/WebJobs.Extensions/Extensions/Files/Config/FilesConfiguration.cs
As the following tutorial has mentioned, FilesConfiguration.RootPath should be set to a valid directory. https://azure.microsoft.com/en-us/blog/extensible-triggers-and-binders-with-azure-webjobs-sdk-1-1-0-alpha1 Please check and make sure that the specified directory is existed in the Web APP which hosts in your WebJob.
Trigger when new files are created in the "clients" folder of the Azure Files via WebJob
As far as I know, there has two triggers for Azure Storage:
The new WebJobs SDK provide a File trigger which could trigger functions based on File events. However, a file trigger could monitor file additions/changes to a particular directory, but there seems to be no trigger for monitor file additons/changes on Azure File Storage.
Upvotes: 2