From 7eff5e0e2d666a94bf240608a05afcbad5f2235f Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Thu, 23 Feb 2017 18:36:02 -0800 Subject: [PATCH] Fix for nanosUntilNextJob() edge case. (#808) 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. --- .../apache/mesos/chronos/scheduler/jobs/JobScheduler.scala | 4 ++-- .../mesos/chronos/scheduler/jobs/JobSchedulerSpec.scala | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobScheduler.scala b/src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobScheduler.scala index 9c910c511..c7b5adb63 100644 --- a/src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobScheduler.scala +++ b/src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobScheduler.scala @@ -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 diff --git a/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerSpec.scala b/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerSpec.scala index 3dcd10116..dabd6d610 100644 --- a/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerSpec.scala +++ b/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerSpec.scala @@ -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] @@ -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 {