0
votes

I am trying to create a job which will run every Saturday at 8 pm using cron expression input to the trigger scheduler. But my job is getting executed every 10 minutes? What on earth have I done wrong here, please help. My app setup stack is 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();
    }
4
@user85421 the same issue persists. looks like some issue in resetting old trigger information perhaps. - Abdullah
My bad, there is nothing wrong with the code. I had another trigger in the DB with a similar name. That was firing every ten minutes. - Abdullah

4 Answers

1
votes

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.

Nevertheless, a job update its configuration at startup.

1
votes

Try setting cron expression 0 0 20 ? * 7 and also adding a timezone

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 is also correct try this and also keep a log in the EmailReportJob class.

0
votes

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.

A useful tool is: CronTab Guru where you can enter your expression and it will output it's result.

0
votes

I do have the same issue with different reason that's why posting this. I have customized the QUARTZ schema with customized tables. For example, JOB_DETAILS, TRIGGERS and CRON_TRIGGERS are actual tables. I created tables with the prefix of QRTZ_ to each table.

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. 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.