【发布时间】:2018-06-14 14:55:09
【问题描述】:
来自这篇文章:
How do I get the current attempt number on a background job in Hangfire?
可以使用魔术字符串“RetryCount”来获取重试次数。
public void SendEmail(PerformContext context, string emailAddress)
{
string jobId = context.BackgroundJob.Id;
int retryCount = context.GetJobParameter<int>("RetryCount");
// send an email
}
如果我需要获取总重试次数怎么办? 我可以使用类似的东西吗:
int retries = context.GetJobParameter<int>("Retries");
或者我如何从“PerformContext”(如果可能的话)中获取该信息?
我需要定义的总重试次数,因此我可以在最后一次重试时执行一些任务。
【问题讨论】: