Hangfire - 获取下一次执行时间

Hangfire - get next execution time

我在 Hangfire 中有一个由 CronTemplate 触发的重复作业。我需要在作业执行期间获得下一次执行时间。

我想到了将 CronTemplate 注入作业并使用一些基于模板的现有库计算该日期的想法,但我对这个解决方案有一些设计问题,我认为一个解决方案基于某种JobExecutionContext 会更好,但到目前为止我找不到任何方法来获取它。

Hangfire 中是否存在类似的东西?如果是这样,我该如何访问它?

如有任何想法,我们将不胜感激。

Alex 这是一些伪代码,可能会回答您的问题。

private DateTime? GetNextExecutionTime(MethodInfo methodInfo)
{
    try
    {
        var job = JobStorage.Current.GetConnection().GetRecurringJobs().Single(x => x.Job.Method == methodInfo);
        return job == null ? null : job.NextExecution;
    }
    catch (Exception)
    {
        return null;
    }
}