Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop or pause Quartz job

I have executed 2 jobs (MyJob1 and MyJob2) as below:

public async Task<ActionResult> ScheduleJob()
    {
        await _jobManager.ScheduleAsync<MyJob1>(
            job =>
            {
                job.WithIdentity("Job1Identity", "MyGroup")
                    .WithDescription("This is job 1");
            },
            trigger =>
            {
                trigger.StartNow()
                    .WithSimpleSchedule(schedule =>
                    {
                        schedule.RepeatForever()
                            .WithIntervalInSeconds(5)
                            .Build();
                    });
            });

        await _jobManager.ScheduleAsync<MyJob2>(
            job =>
            {
                job.WithIdentity("Job2Identity", "MyGroup")
                    .WithDescription("This is job 2");
            },
            trigger =>
            {
                trigger.StartNow()
                    .WithSimpleSchedule(schedule =>
                    {
                        schedule.RepeatForever()
                            .WithIntervalInSeconds(5)
                            .Build();
                    });
            });

        return Content("OK, scheduled!");
    }

--> I have tried to use _jobManager.Stop() but it stops all my job, so how to stop or pause only MyJob2?

like image 238
Hoang Tran Avatar asked Oct 19 '17 10:10

Hoang Tran


1 Answers

Use Scheduler.PauseJob like this:

var scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.PauseJob(new JobKey("Job2Identity", "MyGroup"));
like image 155
aaron Avatar answered Sep 20 '22 18:09

aaron