Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control errors on scheduler start #978

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions dkron/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ RECONCILE:
// Check if we need to handle initial leadership actions
if !establishedLeader {
if err := a.establishLeadership(stopCh); err != nil {
a.logger.WithError(err).Error("dkron: failed to establish leadership")

// Immediately revoke leadership since we didn't successfully
// establish leadership.
if err := a.revokeLeadership(); err != nil {
a.logger.WithError(err).Error("dkron: failed to revoke leadership")
}

a.logger.WithError(err).Fatal("dkron: failed to establish leadership")

// TODO: review this code path
goto WAIT
}

Expand Down Expand Up @@ -185,11 +186,9 @@ func (a *Agent) establishLeadership(stopCh chan struct{}) error {
a.logger.Info("agent: Starting scheduler")
jobs, err := a.Store.GetJobs(nil)
if err != nil {
a.logger.Fatal(err)
return err
}
a.sched.Start(jobs, a)

return nil
return a.sched.Start(jobs, a)
}

// revokeLeadership is invoked once we step down as leader.
Expand Down
4 changes: 3 additions & 1 deletion dkron/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func (s *Scheduler) Start(jobs []*Job, agent *Agent) error {
metrics.IncrCounter([]string{"scheduler", "start"}, 1)
for _, job := range jobs {
job.Agent = agent
s.AddJob(job)
if err := s.AddJob(job); err != nil {
return err
}
}
s.Cron.Start()
s.started = true
Expand Down