Skip to content

Commit

Permalink
implements nitpick comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 22, 2024
1 parent b9f6a0d commit 3350654
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
}

0 comments on commit 3350654

Please sign in to comment.