Skip to content

Commit

Permalink
Merge pull request #90 from vgarvardt/fix/no-jobs-scheduler
Browse files Browse the repository at this point in the history
fix: allow starting a scheduler with no job tyles being registered
  • Loading branch information
vgarvardt committed Jun 14, 2024
2 parents 5e6d6d3 + 042a273 commit d139a40
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (s *Scheduler) jobsToSchedule(since time.Time) (jobs []gue.Job) {
until := since.Add(s.horizon)
for _, ss := range s.schedules {
// We're starting schedule process earlier, because we may get into situation when refresh job and scheduled
// job are ment to run at the same time, but refresh job has higher priority, runs first, puts a global lock,
// job are meant to run at the same time, but refresh job has higher priority, runs first, puts a global lock,
// so that scheduled job can not be executed and is cleaned up. To avoid this - we're starting scheduling jobs a
// bit earlier to restore them.
for now := since.Add(-s.interval); ; {
Expand Down Expand Up @@ -311,6 +311,13 @@ func (s *Scheduler) cleanupScheduledLeftovers(ctx context.Context, tx adapter.Tx
s.logger.Debug("Finished leftovers cleanup")
}()

// it is possible that the scheduler is started w/out any registered jobs - this is fine and there is nothing
// to clean up
if len(s.jobTypes) == 0 {
s.logger.Debug("No job types registered, so no leftovers to clean up")
return nil
}

// It seems that DELETE FROM ... WHERE job_id = ANY(ARRAY(SELECT job_id FROM ... FOR UPDATE SKIP LOCKED))
// does not work, so doing it in two steps - select with FOR UPDATE SKIP LOCKED and then DELETE by IDs.
//
Expand Down

0 comments on commit d139a40

Please sign in to comment.