예제 #1
0
        public static async Task RunOrchestration(
            [OrchestrationTrigger] IDurableOrchestrationContext functionContext,
            ILogger log)
        {
            if (functionContext is null)
            {
                throw new ArgumentNullException(nameof(functionContext));
            }

            if (log is null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            var command       = functionContext.GetInput <OrchestratorProviderDeleteCommand>();
            var commandResult = command.CreateResult();
            var provider      = command.Payload;

            using (log.BeginCommandScope(command, provider))
            {
                try
                {
                    using (await functionContext.LockContainerDocumentAsync(provider).ConfigureAwait(true))
                    {
                        if (!(provider is null))
                        {
                            await functionContext
                            .DeleteProviderAsync(provider)
                            .ConfigureAwait(true);
                        }
                    }
                }
                catch (Exception exc)
                {
                    commandResult ??= command.CreateResult();
                    commandResult.Errors.Add(exc);

                    throw;
                }
                finally
                {
                    var commandException = commandResult.Errors?.ToException();

                    if (commandException is null)
                    {
                        functionContext.SetCustomStatus($"Command succeeded", log);
                    }
                    else
                    {
                        functionContext.SetCustomStatus($"Command failed: {commandException.Message}", log, commandException);
                    }

                    functionContext.SetOutput(commandResult);
                }
            }
        }