How to maintain a job history using Quartz scheduler

后端 未结 3 650
暗喜
暗喜 2021-02-02 02:46

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\'.

3条回答
  •  猫巷女王i
    2021-02-02 03:05

    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, ...);
    }
    

提交回复
热议问题