我正在构建一个持久功能,如果活动在maxNumberOfAttempts
之后失败,我需要创建某种警报
调试时,我看到DurableOrchestrationContext类有一个名为History
的属性,但我无法访问它,因为它是内部的。
在这一点上,我能想到的唯一选项是使用Azure Monitor按ExecutionId对日志进行分组/汇总。我不喜欢这种方法,因为Azure Monitor不应该知道或关心函数中配置的maxNumberOfAttempts
。
有没有其他方法可以做到这一点,我错过了?
我能够通过@peter bons提供的信息来解决这个问题:
当重试未导致对函数a的任何成功调用时抛出CCD_ 4。
下面是一个代码示例:
[FunctionName("MyDurableFunctionOrchestrator")]
public async Task RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log)
{
var retryOptions = new RetryOptions(TimeSpan.FromMinutes(1), 2)
{
BackoffCoefficient = 2
};
var request = context.GetInput<UserRequest>();
var tasks = new List<Task>
{
context.CallActivityWithRetryAsync(nameof(Example1Activity), retryOptions, request),
context.CallActivityWithRetryAsync(nameof(Example2Activity), retryOptions, request)
};
try
{
await Task.WhenAll(tasks);
}
catch(FunctionFailedException e)
{
// Azure Monitor will alert on this
log.LogError(e, "Critical Error: {identity}", request.Identity);
// this will tell us all the tasks that failed
foreach(var task in tasks.FindAll(t => t.IsFaulted))
{
log.LogError(task.Exception, "Failed activity for '{identity}'", request.Identity);
}
}
}