jPOS-EE icon indicating copy to clipboard operation
jPOS-EE copied to clipboard

Possible enhancement to QuartzAdaptor

Open chhil opened this issue 6 years ago • 3 comments

I propose implementing the TriggerListener for the QuartzAdaptor. In the methods we can log info like when the trigger will fire again on trigger fire

e.g.

@Override
    public void triggerFired(Trigger trigger, JobExecutionContext context) {

        LogEvent evt = getLog().createInfo();
        evt.addMessage(getName() + " Trigger Fired and it will fire again at " + trigger.getNextFireTime() + "  "
                + context.getJobDetail());
        Logger.log(evt);

    }

    @Override
    public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
        return false;
    }

    @Override
    public void triggerMisfired(Trigger trigger) {
        LogEvent evt = getLog().createInfo();
        evt.addMessage(getName() + " Trigger MIS-Fired and will fire again at " + trigger.getNextFireTime());
        Logger.log(evt);

    }

I also propose adding a a misfire instruction when the trigger is created. At times the trigger does not fire and we have no clue what happened. The above trigger listener will help with logging the misfire. Based on the default config of "org.quartz.jobStore.misfireThreshold", "60000", if the trigger is not fired in one minutes time it will be treated as a misfire and the instruction withMisfireHandlingInstructionFireAndProceed it will fire the trigger.

This may not suit everyone but can be made configurable to select what to do on a misfire. e.g.

                trigger = TriggerBuilder.newTrigger()
                                        .withIdentity(e.getAttributeValue("id"), getName())
                                        .withSchedule(CronScheduleBuilder.cronSchedule(e.getAttributeValue("when"))
                                                                         .withMisfireHandlingInstructionFireAndProceed())
                                        .build();

chhil avatar May 24 '18 08:05 chhil

Sounds like a good idea @chhil - do you want to provide a PR if you have it running or you want us to take a stab at this implementation?

ar avatar May 25 '18 00:05 ar

I will make a pull request (next week). Its something I did recently so its been locally tested by me. The problem I usually face is with the code formatting. My custom eclipse code formatters will end up making showing a lot more changes, I will try my best to comply with the existing format.

chhil avatar May 25 '18 04:05 chhil

There is one more change that would be nice. Jpos has the QuartzJobSupport , I added a new one called QuartzStatefulJobSupport. They are identical, except the stateful one has class level annotations: @PersistJobDataAfterExecution @DisallowConcurrentExecution

So if an existing job is running, a concurrent one wont be started. Helps to extend your job which runs often and dont want multiple jobs running together.

chhil avatar May 25 '18 04:05 chhil