func (runner *Runner) tick(logger lager.Logger) { logger.Info("start") defer logger.Info("done") config, _, err := runner.DB.GetConfig() if err != nil { logger.Error("failed-to-get-config", err) return } if runner.Noop { return } for _, job := range config.Jobs { lock := []db.NamedLock{db.JobSchedulingLock(runner.DB.ScopedName(job.Name))} jobCheckingLock, err := runner.Locker.AcquireWriteLockImmediately(lock) if err != nil { continue } sLog := logger.Session("scheduling", lager.Data{ "job": job.Name, }) runner.schedule(sLog, job, config.Resources) jobCheckingLock.Release() } }
DB: pipelineDB, Scheduler: scheduler, Noop: noop, Interval: 100 * time.Millisecond, }) }) AfterEach(func() { ginkgomon.Interrupt(process) }) It("acquires the build scheduling lock for each job", func() { Eventually(locker.AcquireWriteLockImmediatelyCallCount).Should(Equal(2)) job := locker.AcquireWriteLockImmediatelyArgsForCall(0) Ω(job).Should(Equal([]db.NamedLock{db.JobSchedulingLock("pipeline:some-job")})) job = locker.AcquireWriteLockImmediatelyArgsForCall(1) Ω(job).Should(Equal([]db.NamedLock{db.JobSchedulingLock("pipeline:some-other-job")})) }) Context("when it can't get the lock for the first job", func() { BeforeEach(func() { locker.AcquireWriteLockImmediatelyStub = func(locks []db.NamedLock) (db.Lock, error) { if locker.AcquireWriteLockImmediatelyCallCount() == 1 { return nil, errors.New("can't aqcuire lock") } return lock, nil } })