Skip to content

Commit 7eff5e0

Browse files
authored
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.
1 parent 5f12f88 commit 7eff5e0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobScheduler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,8 @@ class JobScheduler @Inject()(val taskManager: TaskManager,
627627
def nanosUntilNextJob(scheduledJobs: List[ScheduleBasedJob]): Long = {
628628
scheduledJobs.foreach { job =>
629629
Iso8601Expressions.parse(job.schedule, job.scheduleTimeZone) match {
630-
case Some((_, schedule, _)) =>
631-
if (!job.disabled) {
630+
case Some((repeat, schedule, _)) =>
631+
if (!job.disabled && repeat != 0) {
632632
val nanos = new Duration(DateTime.now(DateTimeZone.UTC), schedule).getMillis * 1000000
633633
if (nanos > 0) {
634634
return nanos

src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerSpec.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ class JobSchedulerSpec extends SpecificationWithJUnit with Mockito {
134134
s"R5/${ISODateTimeFormat.dateTime().print(futureDate2)}/P1D",
135135
"job5",
136136
"CMD")
137+
val jobNoRepititions = ScheduleBasedJob(
138+
s"R0/${ISODateTimeFormat.dateTime().print(DateTime.now(DateTimeZone.UTC))}/P1D",
139+
"job5",
140+
"CMD")
137141

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

158162
nanos = scheduler.nanosUntilNextJob(List(job5))
159163
nanos must beCloseTo(2 * 60 * 60 * 1000000000l, 5000000000l) // within 5s
164+
165+
nanos = scheduler.nanosUntilNextJob(List(jobNoRepititions, job5))
166+
nanos must beCloseTo(2 * 60 * 60 * 1000000000l, 5000000000l) // within 5s
160167
}
161168

162169
"A parent job succeeds and child is enqueued" in {

0 commit comments

Comments
 (0)