john
john

Reputation: 707

How to remove job in Quartz JDBC Store?

I wrote this method to remove a job from Quartz JDBC

public boolean removeJob(String jobName) {
    try {
        JobKey jobKey = JobKey.jobKey(jobName);  
        try {    
            Scheduler sched = schedulerFactoryBean.getScheduler();  
            logger.info("RESULT: " + sched.deleteJob(jobKey)); 
        } catch (Exception e) {    
            throw new RuntimeException(e);    
        }    
        return true; 
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        return false; 
    } 
} 

deleteJob is always returning false. So the job is not getting removed from the JDBC tables in mysql. What am I doing wrong. I only want to completely remove this job from the scheduler

Upvotes: 1

Views: 3234

Answers (1)

Monzurul Shimul
Monzurul Shimul

Reputation: 8386

Have you defined a job group during job creation? Then you may need to call jobKey(jobName, group). You can also check if job exists with scheduler.checkExists(jobKey) method which will be good for debugging.

JobKey jobKey = jobKey(jobName, group);
if (scheduler.checkExists(jobKey)) {
    logger.info("job found with key: {}", jobKey); 
    scheduler.deleteJob(jobKey);
}

Upvotes: 5

Related Questions