简体   繁体   English

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

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

I am trying to create a job which will run every Saturday at 8 pm using cron expression input to the trigger scheduler.我正在尝试创建一个作业,该作业将在每个星期六晚上 8 点运行,使用 cron 表达式输入到触发器调度程序。 But my job is getting executed every 10 minutes?但是我的工作每 10 分钟执行一次? What on earth have I done wrong here, please help.我到底做错了什么,请帮忙。 My app setup stack is Spring Boot + Hibernate.我的应用程序设置堆栈是 Spring Boot + Hibernate。 The code is as follows.代码如下。

    @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();
    }

Try setting cron expression 0 0 20? * 7尝试设置cron 表达式0 0 20? * 7 0 0 20? * 7 and also adding a timezone 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();

Though the cron Expression 0 0 20? * SAT虽然cron 表达式0 0 20? * SAT 0 0 20? * SAT is also correct try this and also keep a log in the EmailReportJob class. 0 0 20? * SAT也是正确的试试这个并在EmailReportJob类中保留一个日志。

most of time you have a job with the same name in the database, which must be updated by another member of the cluster.大多数时候你在数据库中有一个同名的作业,它必须由集群的另一个成员更新。

Either you could try to rename your job (jobkey), or check if the database is not used by someone else.您可以尝试重命名您的工作(jobkey),或者检查数据库是否未被其他人使用。

Nevertheless, a job update its configuration at startup.尽管如此,作业会在启动时更新其配置。

Crontab format:定时任务格式:

# 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

So according to this 0 20 * * sat would run 8:00pm every Saturday.所以根据这个0 20 * * sat将在每个星期六晚上 8:00 运行。

A useful tool is: CronTab Guru where you can enter your expression and it will output it's result.一个有用的工具是: CronTab Guru ,您可以在其中输入表达式并将其输出结果。

`0 20 * * 6 your command line` 

拿着它

I do have the same issue with different reason that's why posting this.我确实有同样的问题,但原因不同,这就是发布此内容的原因。 I have customized the QUARTZ schema with customized tables.我已经使用定制表定制了 QUARTZ 模式。 For example, JOB_DETAILS, TRIGGERS and CRON_TRIGGERS are actual tables.例如,JOB_DETAILS、TRIGGERS 和 CRON_TRIGGERS 是实际的表。 I created tables with the prefix of QRTZ_ to each table.我为每个表创建了前缀为 QRTZ_ 的表。

While starting the application, jobs are getting registered and triggers are getting registered and records are present in tables as expected.在启动应用程序时,作业正在注册,触发器正在注册,并且记录按预期出现在表中。 But, job triggering is not happening in next CRON time interval.但是,作业触发不会在下一个 CRON 时间间隔内发生。 So, what is the mistake I have done is?那么,我犯的错误是什么?

There is a relationship between JOB_DETAILS and TRIGGERS, and TRIGGERS has relationship with CRON_TRIGGERS and etc. I missed to specify the FOREIGN KEY relationship between these tables. JOB_DETAILS 和 TRIGGERS 之间有关系,TRIGGERS 与 CRON_TRIGGERS 等有关系。我没有指定这些表之间的 FOREIGN KEY 关系。

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

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