1

I have the following code in Orchestrator function:

var sourceGroups = await context.CallActivityAsync<AzureADGroup[]>(nameof(SourceGroupsReaderFunction), new SourceGroupsReaderRequest { SyncJob = syncJob, RunId = runId });
        
if (sourceGroups.Length == 0)
{
    await _log.LogMessageAsync(new LogMessage
    {
        RunId = runId,
        Message =
        $"None of the source groups in {syncJob.Query} were valid guids. Marking job as errored."
    });
    await _calculator.SendEmailAsync(syncJob, runId, SyncDisabledNoValidGroupIds, new[] { syncJob.Query });
}

On running this, I see the following error:

Function 'OrchestratorFunction (Orchestrator)' failed with an error. Reason: System.InvalidOperationException: Multithreaded execution was detected. This can happen if the orchestrator function code awaits on a task that was not created by a DurableOrchestrationContext method. More details can be found in this article https://learn.microsoft.com/en-us/azure/azure-functions/durable-functions-checkpointing-and-replay#orchestrator-code-constraints.

What am I missing?

Nagoh
  • 813
  • 2
  • 10
  • 23
user989988
  • 3,006
  • 7
  • 44
  • 91
  • 1
    You must put await _calculator.SendEmailAsync(syncJob, runId, SyncDisabledNoValidGroupIds, new[] { syncJob.Query }); into activity. The reason is that orchestrators may execute multiple times from beggining and the activity functions are used to make sure it wont execute multiple times. Your code would potentially log or send emails multiple times. – Bjorne Jun 27 '21 at 18:40
  • Thank you! In order to make sure that messages are logged only one time from Orchestrator function, what should I do? – user989988 Jun 28 '21 at 17:22
  • Could you please answer https://stackoverflow.com/questions/68168267/avoid-multiple-execution-in-orchestrator-function – user989988 Jun 28 '21 at 18:15
  • To fix the loggning read answer from silent https://stackoverflow.com/questions/66171178/azure-durable-orchestration-function-ilogger-outputs-logs-twice/66171448#66171448 – Bjorne Jul 02 '21 at 08:21

0 Answers0