Quartz.NET触发器:在指定的时间间隔运行一次

发布于 2024-12-07 09:50:17 字数 203 浏览 0 评论 0原文

我在 Windows 服务中使用 Quartz.NET 库来运行日常工作等。我正在使用 AdoJobStore。基本上,我希望我的工作能够在午夜到凌晨 1 点之间的任何时间执行一次。因此,如果服务在午夜停止并且有人在 00:30 启动它,我希望该作业在那时执行(仅一次),但如果服务在凌晨 2 点启动,我不希望该作业在当天执行。

如何将触发器配置为在指定时间间隔内仅运行一次?

I'm using the Quartz.NET library in a Windows service to run a daily job among others. I'm using AdoJobStore. Basically I want my job to be executed once any time between midnight and 1AM for example. So if the service was stopped at midnight and someone starts it at 00:30 I want the job to be executed then (only once) but if the service is started at 2AM I don't want the job to be executed that day.

How can a trigger be configured to run only once in a specified interval?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掐死时间 2024-12-14 09:50:17

看来您需要自定义“失火”行为。来自 Quartz 文档

失火说明

触发器的另一个重要属性是它的“失火指令”。
如果持续触发器“错过”其触发时间,则会发生失火
因为调度程序被关闭,或者因为没有
Quartz 线程池中用于执行作业的可用线程。这
不同的扳机类型有不同的失火指令
给他们。默认情况下,他们使用“智能策略”指令 - 该指令具有
基于触发器类型和配置的动态行为。当
调度程序启动时,它会搜索任何具有以下功能的持久触发器:
失火了,然后它根据每个人的单独情况更新他们
配置失火指令。当您开始在您的系统中使用 Quartz 时
自己的项目,你应该让自己熟悉失败的情况
在给定触发器类型上定义的指令,以及
在他们的 JavaDoc 中进行了解释。有关失火的更多具体信息
将在具体的教程课程中给出说明
每种触发器类型。

不幸的是,您需要的行为不受开箱即用的支持。您需要将作业安排在午夜精确执行,然后实现自定义失火。应该可以使用ITriggerListener.TriggerMisfired

It looks like you need a custom 'misfire' behavior. From Quartz docs:

Misfire Instructions

Another important property of a Trigger is its "misfire instruction".
A misfire occurs if a persistent trigger "misses" its firing time
because of the scheduler being shutdown, or because there are no
available threads in Quartz's thread pool for executing the job. The
different trigger types have different misfire instructions available
to them. By default they use a 'smart policy' instruction - which has
dynamic behavior based on trigger type and configuration. When the
scheduler starts, it searches for any persistent triggers that have
misfired, and it then updates each of them based on their individually
configured misfire instructions. When you start using Quartz in your
own projects, you should make yourself familiar with the misfire
instructions that are defined on the given trigger types, and
explained in their JavaDoc. More specific information about misfire
instructions will be given within the tutorial lessons specific to
each trigger type.

Unfortunately the behavior that you need is not supported out of the box. You would need to schedule your job to execute exactly at midnight and then implement custom misfire. It should be possible to use ITriggerListener.TriggerMisfired.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文