为什么我的石英作业没有根据给定的 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();
    }

Crontab格式:

# 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:00pm。

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

尝试设置 cron 表达式 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 也是正确的,但请尝试此操作并在 EmailReportJob class.[=14 中保留日志=]

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

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

不过,作业会在启动时更新其配置。

我确实遇到了同样的问题,但原因不同,所以才发帖。我已经使用定制的 tables 定制了 QUARTZ 模式。例如,JOB_DETAILS、TRIGGERS 和 CRON_TRIGGERS 是实际的 table。我为每个 table.

创建了带有 QRTZ_ 前缀的 tables

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

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