Существует множество функций оркестрации и активности, а также один «главный» оркестратор, который запускает цепочку вызовов. Этот оркестратор также должен иметь возможность перехватывать исключения и предоставлять исходное сообщение об ошибке и трассировку стека. Демо-код:
Код: Выделить всё
[Function(nameof(MainOrchestrator))]
public static async Task MainOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context, FunctionContext executionContext)
{
string[] cities = ["Seattle", "London"];
try
{
foreach (var city in cities)
{
await context.CallSubOrchestratorAsync(nameof(CityOrchestrator), city);
}
}
catch (TaskFailedException ex)
{
// inspect the exception here
}
}
[Function(nameof(CityOrchestrator))]
public static async Task CityOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context, string city, FunctionContext executionContext)
{
string[] postfixes = ["a", "b"];
foreach (var postfix in postfixes)
{
await context.CallActivityAsync(nameof(SayHello), input: $"{city}-{postfix}");
}
}
[Function(nameof(SayHello))]
public static async Task SayHello([ActivityTrigger] string cityName, FunctionContext executionContext)
{
await Task.Delay(100);
if (cityName == "London-b") throw new Exception("Fire in London!");
}
[Function("Orchestration_HttpStart")]
public static async Task HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
{
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
nameof(MainOrchestrator));
return await client.CreateCheckStatusResponseAsync(req, instanceId);
}
в Microsoft.DurableTask.Worker.Shims.TaskOrchestrationContextWrapper.CallActivityAsync[T] (имя TaskName, ввод объекта, параметры TaskOptions)
в AzureBackground.Orchestration.CityOrchestrator(контекст TaskOrchestrationContext, String city, FunctionContext ExecutionContext) в C:\bb_projekt\DociaBackground\AzureBackgroundTasks\AzureBackground\Orchestration.cs:line 42
в AzureBackground.DirectFunctionExecutor.ExecuteAsync(контекст FunctionContext) в C:\bb_projekt\DociaBackground\AzureBackgroundTasks\AzureBackground\obj\Debug\net8.0\Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions. Worker.Sdk.Generators.FunctionExecutorGenerator\GeneratedFunctionExecutor.g.cs:строка 70
в Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(контекст FunctionContext, FunctionExecutionDelegate следующий) в D:\a_work\1\s \src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:строка 13
в Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) в /mnt/vss/ work/1/s/extensions/Worker.Extensions.Http.AspNetCore/src/FunctionsMiddleware/FunctionsHttpProxyingMiddleware.cs:строка 38
в Microsoft.Azure.Functions.Worker.Extensions.DurableTask.FunctionsOrchestrator.EnsureSynchronousExecution( FunctionContext functionContext, FunctionExecutionDelegate next, FunctionsOrchestrationContext оркестрацииКонтекст) в //src/Worker.Extensions.DurableTask/FunctionsOrchestrator.cs:строка 81
в Microsoft.Azure.Functions.Worker.Extensions.DurableTask.FunctionsOrchestrator.RunAsync (Контекст TaskOrchestrationContext, ввод объекта) в /_/src/Worker.Extensions.DurableTask/FunctionsOrchestrator.cs:строка 51
в Microsoft.DurableTask.Worker.Shims.TaskOrchestrationShim.Execute(OrchestrationContext InternalContext, String rawInput)
Исходная трассировка стека очень важна для бизнес-логики, и я должен каким-то образом получить ее в коде. Как мне это сделать?
Заранее спасибо!
Подробнее здесь: https://stackoverflow.com/questions/786 ... azure-func