Search code examples
javarefactoringaemsling

Sling scheduler method refactor


I have deprecated method Scheduler.addPeriodicJob. I want to refactor my code and replace it with Scheduler.schedule How to do it with ScheduleOptions Interface and how to pass values by it?


Solution

  • Take a look at this page. It looks you need to replace each call like:

    Scheduler s;
    s.addPeriodicJob(name, job, config, period, canRunConcurrently);
    

    with something like

    Scheduler s;
    ScheduleOptions so = Scheduler.NOW(times, period); // times == -1 for endless
    so.canRunConcurrently(canRunConcurrently);
    so.config(config);
    so.name(name);
    s.schedule(job, so);