Azure WebJob FileTrigger 路径 'D:\home\data\...' 不存在
Azure WebJob FileTrigger Path 'D:\home\data\...' does not exist
我创建了一个 WebJob 来在创建文件时从 Azure 文件读取文件。
当我 运行 它在本地工作但当我发布 WebJob 时它不工作。
我的 Main() 函数是:
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();
}
创建文件时触发的函数为:
public void TriggerTest([FileTrigger(@"clients\{name}", "*.txt", WatcherChangeTypes.Created)] Stream file, string name, TextWriter log)
{
log.WriteLine(name + " received!");
// ...
}
我在发布 WebJob 时得到的错误是:
[08/17/2016 00:15:31 > 4df213: ERR ] Unhandled Exception: System.InvalidOperationException: Path 'D:\home\data\clients' does not exist.
想法是让 WebJob 在 Azure 文件的 "clients" 文件夹中创建新文件时触发。
有人可以帮助我吗?
根据你的要求,我这边测试了一下,然后重现了你的问题
Unhandled Exception: System.InvalidOperationException: Path 'D:\home\data\clients' does not exist
发布 WebJob 时,FilesConfiguration.RootPath 将设置为“D:\HOME\DATA”目录,而在 Azure Web App 中 运行。你可以参考源代码:
https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/WebJobs.Extensions/Extensions/Files/Config/FilesConfiguration.cs
如以下教程所述,FilesConfiguration.RootPath 应设置为有效目录。
https://azure.microsoft.com/en-us/blog/extensible-triggers-and-binders-with-azure-webjobs-sdk-1-1-0-alpha1
请检查并确保指定的目录存在于您的 WebJob 中托管的 Web 应用程序中。
Trigger when new files are created in the "clients" folder of the Azure Files via WebJob
据我所知,Azure 存储有两个触发器:
- QueueTrigger - 当 Azure 队列消息入队时。
- BlobTrigger – 上传 Azure Blob 时。
新的WebJobs SDK 提供了一个文件触发器,可以根据文件事件触发函数。
但是,文件触发器可以监视特定目录的文件 additions/changes,但 Azure 文件存储上似乎没有监视文件 additons/changes 的触发器。
在 Azure 环境中,"Web-Jobs" 存储在其本地文件夹中,该文件夹称为“D:\home”和“D:\ local" 是 Web 挂钩使用的本地文件夹。我需要使用一个文件夹来临时使用从 SFTP 服务器下载文件,然后再次从该本地临时位置文件读取文件并在我的应用程序中使用它。
我使用了“D:\local\Temp”作为代码在检查文件夹是否存在后创建的临时文件夹,然后在创建文件夹后代码将从服务器下载文件并存储到此位置,然后从同一位置读取并从该临时文件夹中删除文件。
我创建了一个 WebJob 来在创建文件时从 Azure 文件读取文件。 当我 运行 它在本地工作但当我发布 WebJob 时它不工作。
我的 Main() 函数是:
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();
}
创建文件时触发的函数为:
public void TriggerTest([FileTrigger(@"clients\{name}", "*.txt", WatcherChangeTypes.Created)] Stream file, string name, TextWriter log)
{
log.WriteLine(name + " received!");
// ...
}
我在发布 WebJob 时得到的错误是:
[08/17/2016 00:15:31 > 4df213: ERR ] Unhandled Exception: System.InvalidOperationException: Path 'D:\home\data\clients' does not exist.
想法是让 WebJob 在 Azure 文件的 "clients" 文件夹中创建新文件时触发。
有人可以帮助我吗?
根据你的要求,我这边测试了一下,然后重现了你的问题
Unhandled Exception: System.InvalidOperationException: Path 'D:\home\data\clients' does not exist
发布 WebJob 时,FilesConfiguration.RootPath 将设置为“D:\HOME\DATA”目录,而在 Azure Web App 中 运行。你可以参考源代码: https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/WebJobs.Extensions/Extensions/Files/Config/FilesConfiguration.cs
如以下教程所述,FilesConfiguration.RootPath 应设置为有效目录。 https://azure.microsoft.com/en-us/blog/extensible-triggers-and-binders-with-azure-webjobs-sdk-1-1-0-alpha1 请检查并确保指定的目录存在于您的 WebJob 中托管的 Web 应用程序中。
Trigger when new files are created in the "clients" folder of the Azure Files via WebJob
据我所知,Azure 存储有两个触发器:
- QueueTrigger - 当 Azure 队列消息入队时。
- BlobTrigger – 上传 Azure Blob 时。
新的WebJobs SDK 提供了一个文件触发器,可以根据文件事件触发函数。 但是,文件触发器可以监视特定目录的文件 additions/changes,但 Azure 文件存储上似乎没有监视文件 additons/changes 的触发器。
在 Azure 环境中,"Web-Jobs" 存储在其本地文件夹中,该文件夹称为“D:\home”和“D:\ local" 是 Web 挂钩使用的本地文件夹。我需要使用一个文件夹来临时使用从 SFTP 服务器下载文件,然后再次从该本地临时位置文件读取文件并在我的应用程序中使用它。
我使用了“D:\local\Temp”作为代码在检查文件夹是否存在后创建的临时文件夹,然后在创建文件夹后代码将从服务器下载文件并存储到此位置,然后从同一位置读取并从该临时文件夹中删除文件。