I\'d like to maintain a history of jobs that were scheduled by a Quartz scheduler containing the following properties: \'start time\', \'end time\', \'success\', \'error\'.
The way to do this is to generate an identifier in JobToBeExecuted
, store it in the JobExecutionContext
and retrieve it again from the JobExecutionContext
in JobWasExecuted
.
public void JobToBeExecuted(JobExecutionContext context)
{
// Insert history record and retrieve primary key of inserted record.
long historyId = InsertHistoryRecord(...);
context.Put("HistoryIdKey", historyId);
}
public void JobWasExecuted(JobExecutionContext context,
JobExecutionException jobException)
{
// Retrieve history id from context and update history record.
long historyId = (long) context.Get("HistoryIdKey");
UpdateHistoryRecord(historyId, ...);
}