【发布时间】:2018-12-22 22:17:28
【问题描述】:
Azure Functions 的时间限制为 10 分钟。假设我有一个长时间运行的任务,例如下载一个需要 1 小时才能下载的文件。
[FunctionName("PerformDownload")]
[return: Queue("download-path-queue")]
public static async Task<string> RunAsync([QueueTrigger("download-url-queue")] string url, TraceWriter log)
{
string downloadPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString);
log.Info($"Downloading file at url {url} to {downloadPath} ...");
using (var client = new WebClient())
{
await client.DownloadFileAsync(new Uri(url), myLocalFilePath);
}
log.Info("Finished!");
}
有没有什么技巧可以让这样的事情开始,然后在时间限制到期之前在另一个函数中恢复?或者有没有更好的方法将像这样的长任务集成到使用 Azure Functions 的工作流中?
(稍微相关一点,普通的 Azure Web Jobs 过时了吗?我在资源下找不到它。)
【问题讨论】:
-
当您收到下载文件的请求时,在 blob 存储中创建一个文件并将该链接返回给用户。对你有用吗?
标签: c# azure azure-functions azure-blob-storage