Skip to content

Commit

Permalink
Merge pull request #635 from Califax/remove-schedule-from-scheduled-j…
Browse files Browse the repository at this point in the history
…ob-made-dependent

remove schedules from jobs made dependent when previously scheduled
  • Loading branch information
brndnmtthws committed Mar 28, 2016
2 parents 332a041 + 87c9b23 commit 57647ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class DependentJobResource @Inject()(
}
jobScheduler.removeSchedule(j)
case j: ScheduleBasedJob =>
log.info("Removing schedule for job: %s".format(j))
jobScheduler.removeSchedule(j)
parents.foreach(p => jobGraph.addDependency(p.name, newJob.name))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,30 @@ class JobSchedulerIntegrationTest extends SpecificationWithJUnit with Mockito {
there was no(mockTaskManager).enqueue(TaskUtils.getTaskId(job3, DateTime.parse(vJob2.lastError), 0), highPriority = false)
}

"Tests that scheduled jobs changed to dependent jobs remove their schedules" in {
val epsilon = Minutes.minutes(1).toPeriod
val job1 = new ScheduleBasedJob(schedule = "R/2012-01-01T00:05:00.000Z/PT10M",
name = "job1", command = "fooo", epsilon = epsilon, disabled = false)
val job2 = new ScheduleBasedJob(schedule = "R/2012-01-01T00:05:00.000Z/PT10M",
name = "job2", command = "fooo", epsilon = epsilon, disabled = false)
val horizon = Minutes.minutes(5).toPeriod
val mockTaskManager = mock[TaskManager]
val graph = new JobGraph()
val mockPersistenceStore = mock[PersistenceStore]
val mockedScheduler = mock[JobScheduler]
val scheduler = mockScheduler(horizon, mockTaskManager, graph, mockPersistenceStore)
scheduler.leader.set(true)
val date = DateTime.parse("2012-01-01T00:00:00.000Z")
scheduler.registerJob(job1, persist = true, date)
scheduler.registerJob(job2, persist = true, date)
val dependentJob2 = new DependencyBasedJob(Set("job1"), name = "job2", command = "CMD", disabled = false)
val jobResource = new DependentJobResource(jobScheduler = mockedScheduler, jobGraph = graph)

jobResource.handleRequest(dependentJob2)
there was one(mockedScheduler).removeSchedule(job2)
there was one(mockedScheduler).updateJob(job2, dependentJob2)
}

"Tests that dependent jobs runs when they should after changing the jobgraph" in {
val epsilon = Minutes.minutes(20).toPeriod
val job1 = new ScheduleBasedJob(schedule = "R/2012-01-01T00:01:00.000Z/PT1M",
Expand Down

0 comments on commit 57647ba

Please sign in to comment.