Skip to content

Commit

Permalink
Merge pull request #42 from slider/fix_invalid_crontab_breaking_hajobs
Browse files Browse the repository at this point in the history
Fix invalid cron expressions breaking haJobs when job is manually triggered
  • Loading branch information
bryan-riddle authored Jan 25, 2018
2 parents f729127 + 05690e7 commit 1d85a18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
.idea/
*.iml
37 changes: 21 additions & 16 deletions ha-jobs-core/src/main/scala/de/kaufhof/hajobs/JobManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,32 @@ class JobManager(managedJobs: => Jobs,
jobToSchedule.cronExpression match {
case Some(cronExpression) =>
logger.debug("scheduling job for {}", jobType)
val job = JobBuilder
.newJob(classOf[TriggerPuller])
.usingJobData(TPData(jobType, this).asDataMap)
.build()
if(org.quartz.CronExpression.isValidExpression(cronExpression)) {
val job = JobBuilder
.newJob(classOf[TriggerPuller])
.usingJobData(TPData(jobType, this).asDataMap)
.build()

val jobName = jobType.name
val jobName = jobType.name

val trigger = TriggerBuilder
.newTrigger
.withIdentity(s"$jobName-trigger")
.withSchedule(CronScheduleBuilder
// this will throw an exception if the expression is incorrect
.cronSchedule(cronExpression)
.inTimeZone(schedulesTimeZone)
).build()
val trigger = TriggerBuilder
.newTrigger
.withIdentity(s"$jobName-trigger")
.withSchedule(CronScheduleBuilder
// this will throw an exception if the expression is incorrect
.cronSchedule(cronExpression)
.inTimeZone(schedulesTimeZone)
).build()

scheduler.scheduleJob(job, trigger)
scheduler.scheduleJob(job, trigger)

logger.info("Job '{}' has cron expression '{}', first execution at {}", jobType, trigger.getCronExpression, trigger.getNextFireTime)
logger.info("Job '{}' has cron expression '{}', first execution at {}", jobType, trigger.getCronExpression, trigger.getNextFireTime)

runJobNowIfPreviousRunWasSkipped(cronExpression, jobType).map(_ => ())
runJobNowIfPreviousRunWasSkipped(cronExpression, jobType).map(_ => ())
} else {
logger.info("Invalid cronExpression defined for job {}", jobType)
Future.successful(())
}
case None =>
logger.info("No cronExpression defined for job {}", jobType)
Future.successful(())
Expand Down

0 comments on commit 1d85a18

Please sign in to comment.