0

I have a requirement where I need to process records from excel. I am using durable functions.Orchestrator client is blob trigger. The Orchestrator function will read blob and trigger activity function asynchronously.Problem that I am facing is activity function is getting re-trigger for few records. Also , it is not processing all of the records.

For example , in excel sheet ,if I have 100 rows , then activity function is getting triggered only 80 times (15 are repeats). Below is the code snippet for Orchestrator function. I have binded blob to orchestrator which is not recommended as per documentation. Is the reason it is causing issue. I am new to Azure and I currently exploring.

    [FunctionName("OrchestrationFunction")]
    public async Task RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext context,
       [Blob("input")] CloudBlobContainer container,
        ILogger log)
    {

        log.LogInformation($"Orchestrator triggered : @{DateTime.UtcNow}");

        try
        {
            var accountsProcessing = new List<Task>();
            var blobName = context.GetInput<string>();
            var blobReference = container.GetBlockBlobReference(blobName);

            using var stream = blobReference.OpenRead();
            using StreamReader reader = new StreamReader(stream);

            //Skip first Line as it is header
            reader.ReadLine();
            var currentLine = string.Empty;
            while ((currentLine = reader.ReadLine()) != null)
            {
                if (!context.IsReplaying)
                {
                    log.LogInformation($"Data to process : {currentLine}");
                    Task accountProcess = context.CallActivityAsync<Task>("ProcessRequest",currentLine);
                    accountsProcessing.Add(accountProcess);
                }
            }

            await Task.WhenAll(accountsProcessing);
        }
        catch (Exception e)
        {
            log.LogError($"Exception caught while processing orchestration {e.Message}");
        }

    }
}
  • There are many things that are wrong with your code. An orchestrator function should not be reading a blob. Neither should you have an if condition around a CallActivityAsync as that messes up the history table. You need to remove the if condition and move the blob read to another activity function that the lines as an array to the orchestrator (or something else). – juunas Nov 18 '20 at 14:51
  • Do check the documentation on orchestrator constraints: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-code-constraints – juunas Nov 18 '20 at 14:52
  • Removing binding to Orchestrator function worked. Thanks! – harshit kanjilal Nov 26 '20 at 18:07

0 Answers0