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 interva开发者_如何学运维l?
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
.
精彩评论