Handle JobExecutionException in Quartz.net

后端 未结 3 1658
無奈伤痛
無奈伤痛 2021-02-12 13:34

Probably a stupid question... but here goes anyway...

I have set up quartz, and can schedule jobs, and I can confirm that jobs (implementing the IJob interface) are work

3条回答
  •  无人及你
    2021-02-12 14:00

    As already mentioned, the correct way to "detect" JobExecutionException's on a global level is to implement and register an IJobListener and check if the JobExecutionException parameter in the JobWasExecuted() method is != null.

    However, the problem I had (and judging from the additional comment of the OP, he faced this too) was that Quartz did not handle the JobExecutionException (as it should) which resulted in an unhandled exception killing the application.

    So far, I was using the precompiled DLL from the Quartz.NET 2.0.1 release (.NET3.5) package. To get to the bottom of the problem, i referenced the Quartz project/sourcecode and to my astonishment it was suddenly working?!

    As a point of interest, this is the Quartz library code that executes the IJob and handles the JobExecutionException:

    try {
        if (log.IsDebugEnabled) {
           log.Debug("Calling Execute on job " + jobDetail.Key);
        }
        job.Execute(jec);
        endTime = SystemTime.UtcNow();
    } catch (JobExecutionException jee) {
        endTime = SystemTime.UtcNow();
        jobExEx = jee;
        log.Info(string.Format(CultureInfo.InvariantCulture, "Job {0} threw a JobExecutionException: ", jobDetail.Key), jobExEx);
    } catch (Exception e) {
       // other stuff here...
    }
    

    The next thing was to reference my freshly compiled DLL direcly and this was working as well. Sadly i can't tell you why this works and i currently don't have any time to get into it any further, but maybe this helps someone. Maybe some else can confirm this and even contribute an explanation. It may have something to do with different target platforms (x86/64bit)?

提交回复
热议问题