HangFire重复出现的任务数据

我正在编写一个MVC 5互联网应用程序,并使用HangFire进行重复性任务。

如果我有一个月度重复任务,我怎样才能获得下一个执行时间的值?

这是我的重复任务的代码:

 RecurringJob.AddOrUpdate("AccountMonthlyActionExtendPaymentSubscription", () => accountService.AccountMonthlyActionExtendPaymentSubscription(), Cron.Monthly); 

我可以按如下方式检索作业数据:

 using (var connection = JobStorage.Current.GetConnection()) { var recurringJob = connection.GetJobData("AccountMonthlyActionExtendPaymentSubscription"); } 

但是,我不确定下一步该做什么。

是否有可能获得重复任务的下一个执行时间?

提前致谢。

你很亲密 我不确定是否有更好或更直接的方式来获取这些细节,但Hangfire Dashboard的方式是使用名为GetRecurringJobs()的扩展方法( using Hangfire.Storage;添加到您的导入GetRecurringJobs()

 using (var connection = JobStorage.Current.GetConnection()) { var recurring = connection.GetRecurringJobs().FirstOrDefault(p => p.Id == "AccountMonthlyActionExtendPaymentSubscription"); if (recurring == null) { // recurring job not found Console.WriteLine("Job has not been created yet."); } else if (!recurring.NextExecution.HasValue) { // server has not had a chance yet to schedule the job's next execution time, I think. Console.WriteLine("Job has not been scheduled yet. Check again later."); } else { Console.WriteLine("Job is scheduled to execute at {0}.", recurring.NextExecution); } } 

有两个捕获:

  1. 它返回所有定期作业,您需要从结果中选择适当的记录
  2. 首次创建作业时, NextExecution时间尚不可用(它将为null)。 我相信一旦连接,服务器会定期检查需要安排的重复任务,并且这样做; 在使用RecurringJob.AddOrUpdate(...)或其他类似方法创建时,它们似乎没有立即安排。 如果你需要在创建后立即获得NextExecution值,我不确定你能做什么。 不过,它最终会被填充。