如何缩放天蓝色的持久功能

时间:2020-08-08 02:14:28

标签: azure azure-functions azure-durable-functions

所以我将耐用功能用于2个任务。

  1. 我从sftp下载文件并将其上传到blob。并且我继续在字符串列表中添加这些文件的名称。

  2. 然后我将此列表传递给另一个必须对这些文件执行计算的函数。

     [FunctionName("MainOrch")]
     public async Task<List<string>> RunOrchestrator(
         [OrchestrationTrigger] IDurableOrchestrationContext context)
     {
         var fileUploaded = new List<string>();
    
         // Replace "hello" with the name of your Durable Activity Function.
         fileUploaded = await context.CallActivityAsync<List<string>>("SFTPDownloadAndUpload", null);
         foreach (var fileName in fileUploaded)
         {
             await context.CallActivityAsync("PBARParsing", fileName);
         }
         return fileUploaded;
     }
    

和执行计算的解析功能是这样设置的

  [FunctionName("PBARParsing")]
    public async Task PBARParsing([ActivityTrigger] string name,
        [Blob("pbar-staging/{name}", FileAccess.Read, Connection = "pbarBlobConnectionVault")] Stream myBlob,
        ILogger log)
    {
        try
        {
            log.LogInformation("**********Starting" + name);

我的问题是,它将扩展解析功能,我的意思是,如果将10个文件赋予该功能,它将为每个文件运行10个解析功能实例,还是我必须做其他事情来做到这一点? ?

1 个答案:

答案 0 :(得分:0)

在您当前的代码中,解析活动将一个接一个地依次运行。 这是因为您在循环中等待活动任务。 如果要并行运行所有它们(扇出扇入模式),则需要收集任务并立即等待它们:

 [FunctionName("MainOrch")]
 public async Task<List<string>> RunOrchestrator(
     [OrchestrationTrigger] IDurableOrchestrationContext context)
 {
     var fileUploaded = new List<string>();

     // Replace "hello" with the name of your Durable Activity Function.
     fileUploaded = await context.CallActivityAsync<List<string>>("SFTPDownloadAndUpload", null);

     var parseTasks = new List<Task>(fileUploaded.Count);
     foreach (var fileName in fileUploaded)
     {
         var parseTask = context.CallActivityAsync("PBARParsing", fileName);
         parseTasks.Add(parseTask);
     }

     await Task.WhenAll(parseTasks);

     return fileUploaded;
 }