Quartz.net error when running job with ADOStore

 ̄綄美尐妖づ 提交于 2019-12-06 14:08:31
LeftyX

If you're persisting your jobs (as you do) in a database you cannot create them all the time.
You have to check if they exists at the start-up.

Check my answer here for more details.

When Quartz.Net is initialized and you're using AdoJobStore, the scheduler fetches all the jobs/triggers save in the database.

In your IQuartzScheduler.Run() you should check if the job is present:

this.Scheduler.GetJobDetail()

You can use this bit of code to test if it works:

IJobDetail helloJob = null;
ITrigger helloTrigger = null;

helloJob = this.Scheduler.GetJobDetail(new JobKey("HelloJob", "MyGroup"));

if (helloJob == null)
{
    helloJob = JobBuilder.Create<Jobs.HelloJob>()
        .WithIdentity("HelloJob", "MyGroup")
        .RequestRecovery(true)
        // .StoreDurably(true)
        .Build();

    helloTrigger = TriggerBuilder.Create()
         .WithIdentity("HelloTrigger", "MyGroup")
         .StartNow()
         .WithSimpleSchedule(x => x.RepeatForever().WithIntervalInSeconds(20))
         .Build();

    this.Scheduler.ScheduleJob(helloJob, helloTrigger);
}

this.Scheduler.Start();

If you're using the latest Quartz.Net version there seem to be a problem with the database creation script.

I've noticed that the triggers don't fire. I've then created the database using the latest scripts from Quartz.Net repository on GitHub and it works properly.

Check this answer as well. There are few more details on Quartz.Net + AdoJobStore.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!