diff --git a/src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobUtils.scala b/src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobUtils.scala index 21a4ea6a9..f8aeb044f 100644 --- a/src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobUtils.scala +++ b/src/main/scala/org/apache/mesos/chronos/scheduler/jobs/JobUtils.scala @@ -147,7 +147,7 @@ object JobUtils { protected def calculateSkips(dateTime: DateTime, jobStart: DateTime, period: Period): Int = { // If the period is at least a month, we have to actually add the period to the date // until it's in the future because a month-long period might have different seconds - if (period.getMonths >= 1) { + if (period.getMonths >= 1 || period.getYears >= 1) { var skips = 0 var newDate = new DateTime(jobStart) while (newDate.isBefore(dateTime)) { diff --git a/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobUtilsSpec.scala b/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobUtilsSpec.scala index 32fff280f..d90afc157 100644 --- a/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobUtilsSpec.scala +++ b/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobUtilsSpec.scala @@ -50,6 +50,20 @@ class JobUtilsSpec extends SpecificationWithJUnit with Mockito { scheduledTime.dayOfMonth().get must_== 1 } + "Can skip forward a job with a yearly period" in { + val schedule = s"R/2012-01-01T00:00:01.000Z/P1Y" + val job = new ScheduleBasedJob(schedule, "sample-name", "sample-command") + val now = new DateTime() + + // Get the schedule stream, which should have been skipped forward + val stream = JobUtils.skipForward(job, now) + val scheduledTime = Iso8601Expressions.parse(stream.get.schedule, job.scheduleTimeZone).get._2 + + // Ensure that this job runs on the first of next month + scheduledTime.isAfter(now) must beTrue + scheduledTime.dayOfMonth().get must_== 1 + } + "Can get job with arguments" in { val schedule = "R/2012-01-01T00:00:01.000Z/P1M" val arguments = "--help"