fix(schedule): keep monitors created while reconciliation reads the database

Reconciliation removed every monitor missing from its database read,
including ones created in the meantime; they stayed unscheduled until
the next run a minute later. Upserts now record when they happened and
reconciliation only prunes entries older than its read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 08:48:10 +01:00
1 parent a6126b353e
commit 4f57cafbdd
3 files changed
+54 -10

No files matched your search

+9 -2
View File
@@ -330,9 +330,13 @@ func (s *Server) RunScheduler(ctx context.Context) {
case <-ctx.Done():
return
case <-dispatch.C:
if _, err := s.sched.Dispatch(ctx); err != nil && ctx.Err() == nil {
n, err := s.sched.Dispatch(ctx)
if err != nil && ctx.Err() == nil {
s.log.WarnContext(ctx, "dispatch failed", "error", err)
}
if n > 0 {
s.log.DebugContext(ctx, "dispatched checks", "count", n)
}
case <-reconcile.C:
s.reconcile(ctx)
}
@@ -345,6 +349,9 @@ func (s *Server) reconcile(ctx context.Context) {
if err != nil || !ok {
return
}
// Taken before reading the database: monitors upserted later survive.
start := time.Now()
defer func() { s.log.DebugContext(ctx, "schedule reconciled", "took", time.Since(start)) }()
var rows []store.ListEnabledMonitorsForScheduleRow
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
var err error
@@ -356,7 +363,7 @@ func (s *Server) reconcile(ctx context.Context) {
for i, r := range rows {
want[i] = schedule.Monitor{ID: r.ID, Interval: time.Duration(r.IntervalSeconds) * time.Second, Regions: r.Regions}
}
err = s.sched.Reconcile(ctx, want)
err = s.sched.Reconcile(ctx, want, start)
}
if err != nil && ctx.Err() == nil {
s.log.WarnContext(ctx, "schedule reconciliation failed", "error", err)