From 335065476861e78ca25ec9b98065daaf7fa2c1e6 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 22 Dec 2024 21:18:43 +0000 Subject: [PATCH] implements nitpick comments --- .../scheduler/quartz/service/JobsService.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java index a1b5058e9..8bfae614c 100644 --- a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java +++ b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java @@ -116,7 +116,8 @@ private void addJob(ScheduleJob scheduleJob) throws SchedulerException { // Throw exception if the job already exists if (trigger != null) { - throw new SchedulerException("job already exists!"); + throw new SchedulerException( + "Job already exists with name '" + scheduleJob.jobName() + "' in group '" + GROUP_NAME + "'"); } // simulate job info db persist operation @@ -142,31 +143,41 @@ private void addJob(ScheduleJob scheduleJob) throws SchedulerException { .build(); scheduler.scheduleJob(jobDetail, trigger); + JobKey jobKey = JobKey.jobKey(scheduleJob.jobName(), scheduleJob.jobGroup()); + log.info("Scheduled job with key: {}", jobKey); } public void pauseJob(ScheduleJob scheduleJob) throws SchedulerException { JobKey jobKey = JobKey.jobKey(scheduleJob.jobName(), scheduleJob.jobGroup()); + validateJobExists(jobKey); scheduler.pauseJob(jobKey); + log.info("Paused job with key: {}", jobKey); } public void resumeJob(ScheduleJob scheduleJob) throws SchedulerException { JobKey jobKey = JobKey.jobKey(scheduleJob.jobName(), scheduleJob.jobGroup()); - if (!scheduler.checkExists(jobKey)) { - throw new SchedulerException("Job does not exist"); - } + validateJobExists(jobKey); scheduler.resumeJob(jobKey); + log.info("Resumed job with key: {}", jobKey); } public void runJob(ScheduleJob job) throws SchedulerException { JobKey jobKey = JobKey.jobKey(job.jobName(), job.jobGroup()); - if (!scheduler.checkExists(jobKey)) { - throw new SchedulerException("Job does not exist"); - } + validateJobExists(jobKey); scheduler.triggerJob(jobKey); + log.info("Triggered job with key: {}", jobKey); } public void deleteJob(ScheduleJob scheduleJob) throws SchedulerException { JobKey jobKey = JobKey.jobKey(scheduleJob.jobName(), scheduleJob.jobGroup()); + validateJobExists(jobKey); scheduler.deleteJob(jobKey); + log.info("Deleted job with key: {}", jobKey); + } + + private void validateJobExists(JobKey jobKey) throws SchedulerException { + if (!scheduler.checkExists(jobKey)) { + throw new SchedulerException("Job does not exist with key: " + jobKey); + } } }