Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails - stop or reschedule a job

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!

like image 613
Dvora Avatar asked Jan 22 '26 11:01

Dvora


1 Answers

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);
like image 96
Ak Goel Avatar answered Jan 26 '26 19:01

Ak Goel