Grails - stop or reschedule a job

grails, quartz-scheduler

Solution

you can use Scheduler class having methods unscheduleJob which just delete all the triggers bind with the job. For scheduler class object:

Inject in service

def jobManagerService 

use the code to unschedule the job

jobManagerService.getQuartzScheduler().unscheduleJob(TriggerKey triggerkey)

to start the job scheduling: just create a new trigger for the same job and schedule it.

Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity(triggerName, triggerGroupName)
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds())
                .forJob(JobKey.jobKey(jobName, groupName))
                .build()

        jobManagerService.getQuartzScheduler().scheduleJob(trigger);

Problem

I am dynamically scheduling jobs, at this way: `JobClass.schedule(Long interval, Integer repeatCount, Map params )` Later I want to stop the job from running, and then restart them again according to the users actions. How could I stop this trigger? The only way that did actually stop it was `JobClass.removeJob()`, but I wasn;t able to start it again later, so I need something else. Thanks!

Original source