0

Getting org.quartz.JobPersistenceException error while creating Quartz Job, Trigger on SpringBoot running on Kubernetes and JobDatamap is maintained on PostgresDB / Aurora MySQL running on AWS.

It works for some time like 24 hours then it start failing. And then keeps failing constantly.

@Service
@Slf4j
@Component
public class XYZJobScheduler {
 @Autowired
 private Scheduler scheduler;
 /**
 * Schedule a new job.
 *
 * @param jobName The name of the job
 * @param jobClass The class representing the job
 * @param jobDataMap Data map for job details
 * @throws SchedulerException If there is an issue with scheduling the job
 */
 public void scheduleJobDetail(
 String jobName, Class<? extends Job> jobClass, JobDataMap jobDataMap) {
 try {
 JobKey jobKey = new JobKey(jobName);
 if(scheduler.checkExists(jobKey)){
 log.error("Job with name, jobname={} already exists",jobName);
 return;
 }
 JobDetail jobDetail =
 JobBuilder.newJob(jobClass)
 .withIdentity(jobName)
 .storeDurably()
 .usingJobData(jobDataMap)
 .build();
 scheduler.addJob(jobDetail,false);
 scheduleJobTrigger(jobDataMap, jobDetail, jobName);
 } catch (Exception e) {
 log.error("Error occurred while creating a job, jobName={} error={}", jobName, e);
 }
 }
 /**
 * Schedule a new job with a default trigger that starts now.
 *
 * @param jobDataMap Data map for job details
 * @param jobDetail
 * @param jobName
 */
 private void scheduleJobTrigger(JobDataMap jobDataMap, JobDetail jobDetail, String jobName) {
 try {
 Trigger trigger =
 TriggerBuilder.newTrigger()
 .forJob(jobDetail)
 .withIdentity(jobName)
 .usingJobData(jobDataMap)
 .startNow()
 .build();
 scheduler.scheduleJob(trigger);
 } catch (Exception e) {
 log.error("Exception occurred while executing trigger={}, e={}", jobName, e);
 }
 }

Quartz Configuration

asked Feb 27, 2025 at 13:37

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.