【问题标题】:With Quartz.Net, Is it possible to list all jobs that will be fired on a specific date?使用 Quartz.Net,是否可以列出将在特定日期解雇的所有工作?
【发布时间】:2018-04-22 18:30:15
【问题描述】:

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

说,我创建了如下几个工作:

  • 具有 cron 触发器的作业“A”:“0 0 12 1/1 * ? *”,应在每天 12:00 触发。
  • 作业“B”与 cron 触发器:“0 0 12 ? * MON *”,应在每周一 12:00 触发。
  • 使用 cron 触发器的作业“C”:“0 0 0/1 1/1 * ? *”,应该每小时触发一次。

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

例如:

  • 在下一个星期一,将返回作业“A”、“B”和“C”。并且应该有多个“C”,因为它每小时都会触发一次。

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

【问题讨论】:

    标签: quartz-scheduler quartz.net


    【解决方案1】:

    如果你得到一个用于作业的触发器实例,你可以使用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);
    

    【讨论】:

    • 谢谢,我会尝试这些方法,但是为什么没有内置的解决方案来解决这些问题呢?我认为这是一个非常普遍的要求,不是吗?例如Outlook日历可以列出一天,一周,一个月的所有约会......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 2018-01-26
    相关资源
    最近更新 更多