Fix potential bug with wrongly refreshed crons

This commit is contained in:
Adam Štrauch 2025-01-16 23:13:00 +01:00
parent da09b87020
commit 26e30f2f16
Signed by: cx
GPG key ID: 7262DAFE292BCE20
2 changed files with 16 additions and 2 deletions

View file

@ -52,3 +52,11 @@ tasks:
vars: vars:
DEPLOY_HOST: rosti-merkur DEPLOY_HOST: rosti-merkur
GOARCH: amd64 GOARCH: amd64
- task: deploy
vars:
DEPLOY_HOST: rosti-io
GOARCH: amd64
- task: deploy
vars:
DEPLOY_HOST: rosti-venus
GOARCH: amd64

View file

@ -139,6 +139,8 @@ func (s *Scheduler) do(plan schedulerPlan, done chan schedulerPlan) {
err = s.notifier.Notify(notifyURL) err = s.notifier.Notify(notifyURL)
if err != nil { if err != nil {
log.Printf(".. failed to notify %s: %s", notifyURL, err.Error()) log.Printf(".. failed to notify %s: %s", notifyURL, err.Error())
} else {
log.Printf(".. notification sent to %s", notifyURL)
} }
} else if notifyURL != "" && s.notifier == nil { } else if notifyURL != "" && s.notifier == nil {
log.Println("Warning: No notifier configured, skipping notification") 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 { func (s *Scheduler) footprint(is []incus.Instance, vols []incus.Volume) string {
footprint := "" footprint := ""
for _, inst := range is { for _, inst := range is {
@ -283,6 +286,9 @@ func (s *Scheduler) setupInstanceSchedules(is []incus.Instance, vols []incus.Vol
log.Println("Refreshing scheduler ..") log.Println("Refreshing scheduler ..")
if s.cron != nil { if s.cron != nil {
for _, e := range s.cron.Entries() {
s.cron.Remove(e.ID)
}
s.cron.Stop() s.cron.Stop()
} }
@ -320,7 +326,7 @@ func (s *Scheduler) setupInstanceSchedules(is []incus.Instance, vols []incus.Vol
if sen.Backup { if sen.Backup {
log.Println(".. adding backup schedule for", vol.Project, vol.Pool, vol.Name, sen.BackupSchedule) log.Println(".. adding backup schedule for", vol.Project, vol.Pool, vol.Name, sen.BackupSchedule)
_, err := s.cron.AddFunc(sen.BackupSchedule, func() { _, 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} s.planner <- schedulerPlan{Volume: vol, Reason: planReasonBackupVolume}
}) })
if err != nil { if err != nil {
@ -331,7 +337,7 @@ func (s *Scheduler) setupInstanceSchedules(is []incus.Instance, vols []incus.Vol
if sen.Sync { if sen.Sync {
log.Println(".. adding sync schedule for", vol.Project, vol.Pool, vol.Name, sen.SyncSchedule) log.Println(".. adding sync schedule for", vol.Project, vol.Pool, vol.Name, sen.SyncSchedule)
_, err := s.cron.AddFunc(sen.SyncSchedule, func() { _, 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} s.planner <- schedulerPlan{Volume: vol, Reason: planReasonSyncVolume}
}) })
if err != nil { if err != nil {