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:
1 parent
a6126b353e
commit
4f57cafbdd
3 files changed
+54
-10
No files matched your search
@@ -169,7 +169,7 @@ func TestRemoveAndReconcile(t *testing.T) {
|
||||
_ = s.Upsert(ctx, keep, nil)
|
||||
_ = s.Upsert(ctx, gone, nil)
|
||||
|
||||
if err := s.Reconcile(ctx, []Monitor{keep}); err != nil {
|
||||
if err := s.Reconcile(ctx, []Monitor{keep}, s.now().Add(time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mustDispatch(t, s)
|
||||
@@ -203,3 +203,24 @@ func TestTakeReturnsWhenCancelled(t *testing.T) {
|
||||
t.Errorf("Take() returned %v after cancellation, want within about a second", took)
|
||||
}
|
||||
}
|
||||
|
||||
// TestReconcileKeepsMonitorsCreatedDuringRead covers a monitor created after
|
||||
// reconciliation read the database but before it pruned Redis.
|
||||
func TestReconcileKeepsMonitorsCreatedDuringRead(t *testing.T) {
|
||||
s, now := newTest(t)
|
||||
ctx := context.Background()
|
||||
in := uuid.New()
|
||||
_ = s.Heartbeat(ctx, "eu", in)
|
||||
asOf := *now
|
||||
*now = now.Add(50 * time.Millisecond)
|
||||
fresh := Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}}
|
||||
_ = s.Upsert(ctx, fresh, nil)
|
||||
|
||||
if err := s.Reconcile(ctx, nil, asOf); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mustDispatch(t, s)
|
||||
if got := takeAll(t, s, in); len(got) != 1 || got[0].MonitorID != fresh.ID {
|
||||
t.Errorf("jobs after Reconcile = %+v, want the freshly created monitor", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user