Skip to content

Commit

Permalink
Fix for nanosUntilNextJob() edge case. (#808)
Browse files Browse the repository at this point in the history
If a job has 0 repititions remaining, but the schedule is in the past,
it'll cause the sleep time to be return as 0. This might fix #803.
  • Loading branch information
brndnmtthws authored Feb 24, 2017
1 parent 5f12f88 commit 7eff5e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ class JobScheduler @Inject()(val taskManager: TaskManager,
def nanosUntilNextJob(scheduledJobs: List[ScheduleBasedJob]): Long = {
scheduledJobs.foreach { job =>
Iso8601Expressions.parse(job.schedule, job.scheduleTimeZone) match {
case Some((_, schedule, _)) =>
if (!job.disabled) {
case Some((repeat, schedule, _)) =>
if (!job.disabled && repeat != 0) {
val nanos = new Duration(DateTime.now(DateTimeZone.UTC), schedule).getMillis * 1000000
if (nanos > 0) {
return nanos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class JobSchedulerSpec extends SpecificationWithJUnit with Mockito {
s"R5/${ISODateTimeFormat.dateTime().print(futureDate2)}/P1D",
"job5",
"CMD")
val jobNoRepititions = ScheduleBasedJob(
s"R0/${ISODateTimeFormat.dateTime().print(DateTime.now(DateTimeZone.UTC))}/P1D",
"job5",
"CMD")

val jobGraph = mock[JobGraph]
val persistenceStore = mock[PersistenceStore]
Expand All @@ -157,6 +161,9 @@ class JobSchedulerSpec extends SpecificationWithJUnit with Mockito {

nanos = scheduler.nanosUntilNextJob(List(job5))
nanos must beCloseTo(2 * 60 * 60 * 1000000000l, 5000000000l) // within 5s

nanos = scheduler.nanosUntilNextJob(List(jobNoRepititions, job5))
nanos must beCloseTo(2 * 60 * 60 * 1000000000l, 5000000000l) // within 5s
}

"A parent job succeeds and child is enqueued" in {
Expand Down

0 comments on commit 7eff5e0

Please sign in to comment.