[MGNLSCH-64] Scheduler discards all programatically added jobs on restart Created: 08/Jun/16  Updated: 12/Mar/20  Resolved: 28/Feb/20

Status: Closed
Project: Scheduler
Component/s: None
Affects Version/s: 2.2, 2.3
Fix Version/s: 2.3.3

Type: Bug Priority: Critical
Reporter: Ondrej Chytil Assignee: Mikaël Geljić
Resolution: Fixed Votes: 0
Labels: groovy, publication, scheduler, workflow
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to TASKMGMT-38 Scheduler discards all scheduled publ... Closed
relates to TASKMGMT-34 "The Scheduler has been shutdown" err... Closed
dependency
is depended upon by ABTEST-90 Schedule a test when start date is set Closed
is depended upon by ABTEST-101 Schedule a test when start date is set Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Release notes required:
Yes
Date of First Response:
Epic Link: Support
Sprint: 6.2 Ramp-up 17, 6.2 Ramp-up 18
Story Points: 8

 Description   

Steps to reproduce:

  • add scheduler job by code
    import info.magnolia.module.scheduler.JobDefinition;
    import info.magnolia.module.scheduler.SchedulerModule;
    import info.magnolia.objectfactory.Components;
    import info.magnolia.module.ModuleRegistry;
    
    ModuleRegistry mod = Components.getComponent(ModuleRegistry.class);
    SchedulerModule sch = mod.getModuleInstance("scheduler");
    JobDefinition j = new JobDefinition("test", "default", "activate", "0 0/1 * 1/1 * ? *", null);
    sch.addJob(j);
    
  • job is registered
  • change the scheduler module configuration
  • module is restarted and N2B mechanism initializes all the jobs defined in JCR
  • which wipes out all the jobs registered by the code


 Comments   
Comment by Richard Gange [ 20/Jan/20 ]

I think one way to workaround this issue is to turn the groovy script into a groovy command. After that you will need an observation job (w/ a delay) that watches the scheduler config for changes. If it changes, call the groovy command from the observation job.

Comment by Mikaël Geljić [ 28/Feb/20 ]

Resolved in two parts:

  • The Scheduler module now takes care of restoring global SchedulerListeners (not jobs), whenever a new Quartz Scheduler instance is created.
  • Consumer modules which schedule jobs in future should implement a SchedulerListener to restore applicable jobs & triggers when scheduler restarts. See an example below, for example from a Module#start:
SchedulerListener resumeJobs = new SchedulerListenerSupport() {
    @Override
    public void schedulerStarted() {
        // scheduler.addJob(...)
    }
};
 
if (scheduler.isStarted()) {
    // if already started (likely upon startup), resume straight
    resumeJobs.schedulerStarted();
}
if (!scheduler.getListenerManager().getSchedulerListeners().contains(resumeJobs)) {
    scheduler.getListenerManager().addSchedulerListener(resumeJobs);
}
Generated at Mon Feb 12 10:45:32 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.