我是 azure web 函数的新手,我似乎无法在同一个项目中找到有关多个触发器的任何文档。我已经创建了我的解决方案,并且已经创建了一个很好的TimerTrigger,它工作正常。
此触发器从 ftp 目录下载文件,然后将文件上传到我们的 azure 存储帐户。代码如下所示:
[DependencyInjectionConfig(typeof(DependencyInjectionConfig))]
public class FtpTrigger
{
[FunctionName("EOrderTimerTrigger")]
public static async Task Run(
[TimerTrigger("*/15 * * * * *")]TimerInfo myTimer,
TraceWriter log,
[Inject]IConfig config,
[Inject]SmartFileClient smartFileClient,
[Inject]SettingsHandler settingsHandler,
[Inject]StorageHandler storageHandler)
{
if (myTimer.IsPastDue)
log.Info("Timer is running late!");
log.Info($"Listing directories from { config.FtpUrl }");
var accounts = await smartFileClient.ListDirectories(config.FtpPath);
if (!accounts.Any())
{
log.Warning($"There are no files waiting to be processed for any account");
return;
}
foreach (var account in accounts)
{
try
{
log.Info($"Retrieving settings for { account }");
var url = $"{config.ApiBaseUrl}/{config.ApiSettingsPath}";
var settings = await settingsHandler.GetAsync(url, account);
log.Info($"Find all order files for { account }");
var fileNames = await smartFileClient.ListFiles($"{config.FtpPath}/{account}", settings.OrderFileSuffix.Replace(".", ""));
if (!fileNames.Any())
{
log.Warning($"No files to process for { account }");
continue;
}
log.Info($"Get a list of files awaiting to be processed for { account }");
var awaiting = await storageHandler.ListAsync(config.StorageProcessingContainer, account);
foreach(var fileName in fileNames)
{
log.Info($"Finding any files awaiting to be processed in the storage account for { account }");
var friendlyName = Regex.Replace(fileName, "[^a-zA-Z0-9_.]+", "", RegexOptions.Compiled); ;
var match = awaiting.Any(m => m.Equals(friendlyName));
if (match)
{
log.Warning($"File ({fileName}) already awaiting to be processed for { account }");
continue;
}
log.Info($"Download { fileName } from the ftp directory for { account }");
var bytes = await smartFileClient.DownloadFile($"{config.FtpPath}/{account}", fileName);
log.Info($"Upload { fileName } to the Azure Storage account for { account }");
await storageHandler.UploadAsync(friendlyName, bytes, config.StorageProcessingContainer, account);
log.Info($"Delete { fileName } from the ftp directory for { account }");
if (!await smartFileClient.DeleteFile($"{config.FtpPath}/{account}", fileName))
log.Error($"Failed to delete { fileName } from the ftp directory for { account }");
}
} catch (Exception ex)
{
log.Error($"{ ex.Message }");
}
}
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
现在我想添加第二个触发器。这个触发器将是一个BlobTrigger。我将它添加到我的项目中并运行它,即使创建了文件,它也从未触发过。所以我意识到我一定做错了什么。
有人能告诉我如何在一个项目中有多个触发器吗?如果做不到;什么是替代方案?