Quartz.net 触发器不触发 [英] Quartz.net trigger doesn't fire

查看:87
本文介绍了Quartz.net 触发器不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个任务.第一个应该每小时执行一次,第二个应该在每天 12:00 执行.第一个任务的触发器工作正常,但第二个任务只有在目标时间前几分钟创建时才会触发.我做错了什么?

I have two tasks. The first should be execute once an hour, and the second every day at 12:00. The trigger of the first task works fine, but the second fires only if it is created a few minutes before the target time. What am I doing wrong?

配置第一:

IJobDetail job = JobBuilder.Create<WatchJob>()
    .WithIdentity("Job_1", "First")
    .WithDescription("Job_1_First")
    .UsingJobData("AppData", JsonConvert.SerializeObject("Job_1_First"))
    .Build();

ITrigger trigger = TriggerBuilder.Create()
    .WithIdentity("Trigger_1", "First")
    .StartNow()
    .WithSimpleSchedule(x => x
    .WithIntervalInMinutes(1440)
    .RepeatForever())
    .Build();

第二个:

    IJobDetail updateJob = JobBuilder.Create<UpdateJob>()
        .WithIdentity("Job_1", "Second")
        .WithDescription("Job_1_Second")
        .UsingJobData("AppData", JsonConvert.SerializeObject("Job_1_Second"))
        .Build();

    ITrigger updateTrigger = TriggerBuilder.Create()
        .WithIdentity("Trigger_1", "Second")
        .WithDailyTimeIntervalSchedule
            (t => t
                .WithIntervalInHours(24)
                .OnEveryDay()
                .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(12, 0))
            )
        .Build();

调度程序配置:

<quartz>
  <add key="quartz.scheduler.instanceName" value="Test" />
  <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
  <add key="quartz.threadPool.threadCount" value="1" />
  <add key="quartz.threadPool.threadPriority" value="2" />
  <add key="quartz.jobStore.misfireThreshold" value="60000" />
  <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
</quartz>

推荐答案

您的触发器定义似乎没有问题.但是 Quartz(2.x) 并没有写得很好,有时会表现得很奇怪.您的第二个触发器是 CronTrigger,可以用其他方式定义.

It seems nothing wrong with your Trigger definition. But Quartz(2.x) is not so well written under the hood and can sometimes act really strange. Your second Trigger is a CronTrigger and can defined in an other way.

这对我有用:

 ITrigger updateTrigger = TriggerBuilder.Create()
    .WithIdentity("Trigger_1", "Second")
    .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(12, 0))
    // this line tells quartz to start the trigger immediately, you can remove it, if you don't want this behaviour
    .StartAt(DateTime.Now.AddDays(-1)) 
    .Build();

这篇关于Quartz.net 触发器不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆