4

I'm using Quartz.NET 2.1.2 in my project. In most cases ICronTrigger is being used (for example one of the triggers is set to fire every day at 4 AM). Because it is crucial not to skip job execution, each job is created with RequestRecovery set to true.

IJobDetail jobDetail = JobBuilder.Create<ReportCreationJob>()
.RequestRecovery(true)
.Build();

Trigger could be little off the schedule if the power was off, or the system was to busy to process requests but it is crucial that eventually every job if finished successfully. And every missfire is being processed!

It is important to job's business logic that ScheduledFireTimeUtc (in this case 4 AM) is passed to job. Everything works fine because this information is passed with IJobExecutionContext except in one situation, and that is when recovery jobs are being executed (situations when power was off, Quartz Scheduler crashed,...).

Recovery jobs have different time stamps set in context in comparison with original trigger. Is there a way to retrieve ScheduledFireTimeUtc which is same as in original Trigger.

There is workaround to retrieve this information from context.Trigger.FinalFireTimeUtc but only when recovery of original job is created. But if Scheduler crashes again during this recovery job then "recovery of recovery job" is being created and original ScheduledFireTimeUtc is lost.

I will add additional info from testing client below.

Line of code printing IJobExecutionContext :

string.Format("****{0}Job {1} with {0}Scheduled time={4} {0}Fired at={2} {0}Next scheduled time={3} {0}Recovering={5} {0}FinalFireTimeUtc={6} {0}***",
    Environment.NewLine,
    context.JobDetail.Key,
    context.FireTimeUtc.HasValue ? context.FireTimeUtc.Value.ToString("r") : "NULL",
    context.NextFireTimeUtc.HasValue ? context.NextFireTimeUtc.Value.ToString("r") : "NULL",
    context.ScheduledFireTimeUtc.HasValue ? context.ScheduledFireTimeUtc.Value.ToString("r") : "NULL",
    context.Recovering,
    context.Trigger.FinalFireTimeUtc.HasValue ? context.Trigger.FinalFireTimeUtc.Value.ToString("r") : "NULL");

Test results when recovery of original trigger is executed (Tue, 23 Apr 2013 09:45:30 GMT is original scheduled time) :

***
Job TestGroup.Test10 with 
Scheduled time=Tue, 23 Apr 2013 09:51:05 GMT 
Fired at=Tue, 23 Apr 2013 09:51:45 GMT 
Next scheduled time=NULL 
Recovering=True 
FinalFireTimeUtc=Tue, 23 Apr 2013 09:45:30 GMT 
***

Test results when recovery of recovery trigger is executed (Tue, 23 Apr 2013 09:45:30 GMT is original scheduled time but it is lost in recovery cascade) :

***
Job TestGroup.Test10 with 
Scheduled time=Tue, 23 Apr 2013 10:52:07 GMT 
Fired at=Tue, 23 Apr 2013 10:52:17 GMT 
Next scheduled time=NULL 
Recovering=True 
FinalFireTimeUtc=Tue, 23 Apr 2013 09:51:05 GMT
***
Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99

0 Answers0