使用Quartz.Net,是否可以列出将在特定日期触发的所有作业?

时间:2018-04-22 01:16:50

标签: quartz-scheduler quartz.net

我是Quartz的新手。我不知道是否有任何解决方案可以获得将在特定日期解雇的所有工作?

说,我创建了以下几项工作:

  • 带有cron触发器的作业“A”:“0 0 12 1/1 *?*”,应每天在12:00开除。
  • 带有cron触发器的作业“B”:“0 0 12?* MON *”,应在每周一中午12点解雇。
  • 带有cron触发器的作业“C”:“0 0 0/1 1/1 *?*”,应该每小时触发一次。

现在,是否有任何解决方案可以帮助我获得在特定日期开火的所有工作?

例如:

  • 在下一个星期一,将返回作业“A”,“B”和“C”。并且应该有多个“C”,因为它将每小时被解雇。

  • 在下一个星期五,将返回作业“A”和“C”。并且应该有多个“C”,因为它将每小时被解雇。

1 个答案:

答案 0 :(得分:0)

如果您获得了用于作业的触发器实例,则可以使用ITrigger interface中定义的以下方法:

// Returns the next time at which the Quartz.ITrigger will fire, after the given
// time. If the trigger will not fire after the given time, null will be returned.
DateTimeOffset? GetFireTimeAfter(DateTimeOffset? afterTime);


// Summary:
// Returns the next time at which the Quartz.ITrigger is scheduled to fire. If the
// trigger will not fire again, null will be returned. Note that the time returned
// can possibly be in the past, if the time that was computed for the trigger to
// next fire has already arrived, but the scheduler has not yet been able to fire
// the trigger (which would likely be due to lack of resources e.g. threads).
//
// Remarks:
// The value returned is not guaranteed to be valid until after the Quartz.ITrigger
// has been added to the scheduler.
DateTimeOffset? GetNextFireTimeUtc();

使用作业名称获取触发器:

JobKey jobKey = new JobKey("<job name>");
var triggers = await scheduler.GetTriggersOfJob(jobKey);