我正在基于监视器模式构建一个持久功能。我有下面的代码,我的问题是关于我用于简单指数重试回退的计数器变量。
[FunctionName("RequestOrchestrator")]
public static async Task RequestOrchestrator(
[OrchestrationTrigger] DurableOrchestrationContext monitorContext, ILogger log)
{
DateTime endTime = monitorContext.CurrentUtcDateTime.AddHours(1);
int counter = 0;
while (monitorContext.CurrentUtcDateTime < endTime)
{
var result = await monitorContext.CallActivityAsync<bool>("GetStatusExternal", "test");
if (result)
{
// all ok
break;
}
else
{
counter++;
// Wait for the next checkpoint with exponential backoff
var nextCheckpoint = monitorContext.CurrentUtcDateTime.AddSeconds(5 * counter);
if (!monitorContext.IsReplaying)
{
log.LogInformation($"Next check at {nextCheckpoint}.");
}
await monitorContext.CreateTimer(nextCheckpoint, CancellationToken.None);
}
}
}
计数器的使用是这样还是counter++
需要进入
if (!monitorContext.IsReplaying)
counter++;
它是重播安全的吗?