Using Quartz 2.3.0
As the title asks:
Is there a way to get or compute the previously scheduled fire time for a Quartz Trigger from the Job.execute(JobExecutionContext context)
method?
I know I can use JobExecutionContext.getScheduledFireTime()
to get the scheduled time that this trigger was currently fired for, but I want the scheduled time of the previous fire. Another way to put it: getFireTime()
is to getScheduledFireTime()
as getPreviousFireTime()
is to what?
I am using JobStoreTX
and need to remain database agnostic; It would be quite a pain to override all the JDBC Delegates and the Job Store implementations to store and expose the previous scheduled fire time.
The closest I've come is that some of the Trigger
implementations, such as SimpleTriggerImpl
have a method:
/**
* <p>
* Returns the last time at which the <code>SimpleTrigger</code> will
* fire, before the given time. If the trigger will not fire before the
* given time, <code>null</code> will be returned.
* </p>
*/
public Date getFireTimeBefore(Date end);
But CronTriggerImpl
has:
/**
* NOT YET IMPLEMENTED: Returns the time before the given time
* that this <code>CronTrigger</code> will fire.
*/
protected Date getTimeBefore(Date eTime) {
return (cronEx == null) ? null : cronEx.getTimeBefore(eTime);
}
and unfortunately I will primarily be using CronTrigger
, and there is no method like this in the Trigger
interface.
Any ideas?
Thanks.
My backup idea is, at the start of each job execution, transactionally reading the previous scheduled time from a separate table and writing the new current scheduled time to that table indexed by SchedulerName, TriggerGroup, and TriggerName.