繁体   English   中英

为什么我的石英作业没有根据给定的 cron 表达式触发,而是每 10 分钟触发一次?

[英]Why is my quartz job not getting triggered according to given cron expression, instead firing every 10 minutes?

我正在尝试创建一个作业,该作业将在每个星期六晚上 8 点运行,使用 cron 表达式输入到触发器调度程序。 但是我的工作每 10 分钟执行一次? 我到底做错了什么,请帮忙。 我的应用程序设置堆栈是 Spring Boot + Hibernate。 代码如下。

    @Bean(name = "emailReportJobDetail")
    public JobDetail emailReportJobDetail() {
        return newJob().ofType(EmailReportJob.class).storeDurably().withIdentity(JobKey.jobKey("Qrtz_EmailReportProcessor")).withDescription("Invoke EmailReportProcessor Job service...").build();
    }

    @Bean
    public Trigger emailReportTrigger(@Qualifier("emailReportJobDetail") JobDetail job) {

        logger.info("Configuring emailReportTrigger to fire every Saturday 8 PM GMT");

        return newTrigger().forJob(job).withIdentity(TriggerKey.triggerKey("Qrtz_EmailReportProcessor")).withDescription("EmailReportProcessor trigger")
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 20 ? * SAT")
                )
                .build();
    }

尝试设置cron 表达式0 0 20? * 7 0 0 20? * 7并添加时区

return  newTrigger()
        .forJob(job)
        .withIdentity(TriggerKey.triggerKey("Qrtz_EmailReportProcessor"))
        .inTimeZone(TimeZone.getTimeZone(YOUR_TIME_ZONE))
        .withDescription("EmailReportProcessor trigger")
        .withSchedule(CronScheduleBuilder.cronSchedule("0 0 20 ? * 7"))
        .build();

虽然cron 表达式0 0 20? * SAT 0 0 20? * SAT也是正确的试试这个并在EmailReportJob类中保留一个日志。

大多数时候你在数据库中有一个同名的作业,它必须由集群的另一个成员更新。

您可以尝试重命名您的工作(jobkey),或者检查数据库是否未被其他人使用。

尽管如此,作业会在启动时更新其配置。

定时任务格式:

# 1. Entry: Minute when the process will be started [0-60]
# 2. Entry: Hour when the process will be started [0-23]
# 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
# 4. Entry: Month of the year when the process will be started [1-12]
# 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday] or 
            use sun, mon, tue, wed, thu, fri, or sat
#
# all x min = */x

所以根据这个0 20 * * sat将在每个星期六晚上 8:00 运行。

一个有用的工具是: CronTab Guru ,您可以在其中输入表达式并将其输出结果。

`0 20 * * 6 your command line` 

拿着它

我确实有同样的问题,但原因不同,这就是发布此内容的原因。 我已经使用定制表定制了 QUARTZ 模式。 例如,JOB_DETAILS、TRIGGERS 和 CRON_TRIGGERS 是实际的表。 我为每个表创建了前缀为 QRTZ_ 的表。

在启动应用程序时,作业正在注册,触发器正在注册,并且记录按预期出现在表中。 但是,作业触发不会在下一个 CRON 时间间隔内发生。 那么,我犯的错误是什么?

JOB_DETAILS 和 TRIGGERS 之间有关系,TRIGGERS 与 CRON_TRIGGERS 等有关系。我没有指定这些表之间的 FOREIGN KEY 关系。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM