From 26e30f2f16fe6b3470245361fcbec44790fb77d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Thu, 16 Jan 2025 23:13:00 +0100 Subject: [PATCH] Fix potential bug with wrongly refreshed crons --- Taskfile.yml | 8 ++++++++ scheduler/main.go | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index f57334d..cf34064 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -52,3 +52,11 @@ tasks: vars: DEPLOY_HOST: rosti-merkur GOARCH: amd64 + - task: deploy + vars: + DEPLOY_HOST: rosti-io + GOARCH: amd64 + - task: deploy + vars: + DEPLOY_HOST: rosti-venus + GOARCH: amd64 diff --git a/scheduler/main.go b/scheduler/main.go index c06c27a..b338f06 100644 --- a/scheduler/main.go +++ b/scheduler/main.go @@ -139,6 +139,8 @@ func (s *Scheduler) do(plan schedulerPlan, done chan schedulerPlan) { err = s.notifier.Notify(notifyURL) if err != nil { log.Printf(".. failed to notify %s: %s", notifyURL, err.Error()) + } else { + log.Printf(".. notification sent to %s", notifyURL) } } else if notifyURL != "" && s.notifier == nil { log.Println("Warning: No notifier configured, skipping notification") @@ -239,6 +241,7 @@ func (s *Scheduler) Run() error { } } +// Footprint is something like a hash of current config that is used to determine if the scheduler needs to be refreshed func (s *Scheduler) footprint(is []incus.Instance, vols []incus.Volume) string { footprint := "" for _, inst := range is { @@ -283,6 +286,9 @@ func (s *Scheduler) setupInstanceSchedules(is []incus.Instance, vols []incus.Vol log.Println("Refreshing scheduler ..") if s.cron != nil { + for _, e := range s.cron.Entries() { + s.cron.Remove(e.ID) + } s.cron.Stop() } @@ -320,7 +326,7 @@ func (s *Scheduler) setupInstanceSchedules(is []incus.Instance, vols []incus.Vol if sen.Backup { log.Println(".. adding backup schedule for", vol.Project, vol.Pool, vol.Name, sen.BackupSchedule) _, err := s.cron.AddFunc(sen.BackupSchedule, func() { - log.Printf(".. placing volume backup of %s%s%s into the queue", vol.Project, vol.Pool, vol.Name) + log.Printf(".. placing volume backup of %s/%s/%s into the queue", vol.Project, vol.Pool, vol.Name) s.planner <- schedulerPlan{Volume: vol, Reason: planReasonBackupVolume} }) if err != nil { @@ -331,7 +337,7 @@ func (s *Scheduler) setupInstanceSchedules(is []incus.Instance, vols []incus.Vol if sen.Sync { log.Println(".. adding sync schedule for", vol.Project, vol.Pool, vol.Name, sen.SyncSchedule) _, err := s.cron.AddFunc(sen.SyncSchedule, func() { - log.Printf(".. placing volume sync of %s%s%s into the queue", vol.Project, vol.Pool, vol.Name) + log.Printf(".. placing volume sync of %s/%s/%s into the queue", vol.Project, vol.Pool, vol.Name) s.planner <- schedulerPlan{Volume: vol, Reason: planReasonSyncVolume} }) if err != nil {