0

I have an orchestration function as follows:

        [FunctionName(nameof(OrchestratorFunction))]
        public async Task RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            _ = _loggingRepository.LogMessageAsync(new LogMessage { Message = $"{nameof(OrchestratorFunction)} function started" });
            var syncJobs = await context.CallActivityAsync<List<SyncJob>>(nameof(SyncJobsReaderFunction), null);
            if (syncJobs != null && syncJobs.Count > 0)
            {
                // Run multiple sync job processing flows in parallel
                var processingTasks = new List<Task>();
                foreach (var syncJob in syncJobs)
                {
                    syncJob.RunId = _graphGroupRepository.RunId = Guid.NewGuid();  
                    _loggingRepository.SyncJobProperties = syncJob.ToDictionary(); 
                    Task processTask = context.CallSubOrchestratorAsync(nameof(SubOrchestratorFunction), syncJob);
                    processingTasks.Add(processTask);
                }
                await Task.WhenAll(processingTasks);               
            }
            _ = _loggingRepository.LogMessageAsync(new LogMessage { Message = $"{nameof(OrchestratorFunction)} function completed" });
        }

Notice the following 2 lines:

syncJob.RunId = _graphGroupRepository.RunId = Guid.NewGuid();  
_loggingRepository.SyncJobProperties = syncJob.ToDictionary();

I generate a new GUID that is associated with each syncJob and such that it is easier to see the logs associated with a syncJob using that GUID. On running this code, I see a warning:

 warning DF0102: 'Guid.NewGuid' violates the orchestrator deterministic code constraint. 

Why is that? How do I resolve that? Please suggest an example.

user989988
  • 3,006
  • 7
  • 44
  • 91
  • 2
    Does this solve your issue: https://stackoverflow.com/questions/64854856/how-can-i-safely-generate-guids-within-an-azure-durable-function – Rufus L Jun 12 '21 at 02:19
  • more documentation here: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-code-constraints – fenixil Jun 12 '21 at 04:00
  • Thank you! warning DF0102: 'Guid.NewGuid' violates the orchestrator deterministic code constraint. I was going through article to understand about the above warning. The article says that 'These restrictions apply only to orchestrator functions. Other function types don't have such restrictions.'. Does that mean I could use Guid.NewGuid in SubOrchestrator? – user989988 Jun 12 '21 at 04:14

1 Answers1

2

The IDurableOrchestrationContext provides a method NewGuid that is safe for replay in orchestrator functions. Instead of using 'Guid.NewGuid()' you should be using 'context.NewGuid()' in your orchestrator function.

Example- syncJob.RunId = _graphGroupRepository.RunId = context.NewGuid();

akg179
  • 1,287
  • 1
  • 6
  • 14