Skip to content

Commit 01dcedb

Browse files
committed
fix(notification): preserve watchdog on reschedule failure
1 parent 7cb52b8 commit 01dcedb

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

notification/job.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,18 +558,32 @@ func SyncWatchdogJob(ctx context.Context, scheduler *cron.Cron, notificationID s
558558
if schedule != nil {
559559
scheduleChanged = existingJob.Schedule != *schedule
560560
}
561+
}
561562

562-
if schedule == nil || scheduleChanged {
563+
if schedule == nil {
564+
if existingJob != nil {
563565
ctx.Debugf("deleting existing watchdog job for %s", notificationID)
564566
existingJob.Unschedule()
565567
watchdogJobs.Delete(notificationID)
566568
}
569+
return nil
567570
}
568571

569-
if schedule != nil && (scheduleChanged || existingJob == nil) {
572+
if existingJob == nil {
570573
return scheduleWatchdogJob(ctx, scheduler, notificationID, *schedule)
571574
}
572575

576+
if !scheduleChanged {
577+
return nil
578+
}
579+
580+
if err := scheduleWatchdogJob(ctx, scheduler, notificationID, *schedule); err != nil {
581+
return err
582+
}
583+
584+
ctx.Debugf("deleting existing watchdog job for %s after replacement", notificationID)
585+
existingJob.Unschedule()
586+
573587
return nil
574588
}
575589

notification/watchdog_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ var _ = ginkgo.Describe("Notification watchdog", func() {
7777
Expect(scheduler.Entries()).To(BeEmpty())
7878
})
7979

80+
ginkgo.It("should keep the existing watchdog when schedule update fails", func() {
81+
scheduler := cron.New()
82+
ginkgo.DeferCleanup(func() {
83+
scheduler.Stop()
84+
})
85+
86+
notificationID := uuid.New().String()
87+
schedule := "*/1 * * * *"
88+
Expect(notification.SyncWatchdogJob(DefaultContext, scheduler, notificationID, &schedule)).To(BeNil())
89+
Expect(scheduler.Entries()).To(HaveLen(1))
90+
91+
invalidSchedule := "not-a-cron-expression"
92+
Expect(notification.SyncWatchdogJob(DefaultContext, scheduler, notificationID, &invalidSchedule)).To(HaveOccurred())
93+
Expect(scheduler.Entries()).To(HaveLen(1))
94+
})
95+
8096
ginkgo.It("should resolve watchdog statistics from the event id", func() {
8197
notif := createWatchdogNotification()
8298

0 commit comments

Comments
 (0)