Skip to content

Commit dbc9c40

Browse files
authored
fix(schedules): tolerate older servers' schedule responses and keep 15-minute drains on cadence (#10646)
- Default disabledReason to null in schedule responses so a new client tolerates an older server during rollout - Widen the every-15-minutes drain buffer to 7 minutes so a run that starts late keeps the next tick
1 parent 88dbf15 commit dbc9c40

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

‎apps/docs/content/docs/platform/enterprise/data-drains.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ The detail page shows the last ten runs with status, trigger, time, row count, b
2121

2222
## Cadence and latency
2323

24-
The scheduler checks for due drains every 15 minutes. Each drain runs only when its own cadence has elapsed since its last claimed run, minus a small buffer for scheduler drift:
24+
The scheduler checks for due drains every 15 minutes. Each drain runs only when its own cadence has elapsed since its last claimed run, minus a buffer for scheduler drift and queueing delay:
2525

2626
| Cadence | Runs when the last run started at least |
2727
| --- | --- |
28-
| **Every 15 minutes** | 13 minutes ago |
28+
| **Every 15 minutes** | 8 minutes ago |
2929
| **Every hour** | 55 minutes ago |
3030
| **Every day** | 23 hours 55 minutes ago |
3131

‎apps/sim/lib/api/contracts/schedules.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ export const workflowScheduleRowSchema = z.object({
6767
status: scheduleStatusSchema,
6868
/**
6969
* Why Sim turned the schedule off. Null while it is active or completed, and
70-
* when a person disabled it.
70+
* when a person disabled it. Defaulted so a new client tolerates an old
71+
* server's response during rollout.
7172
*/
72-
disabledReason: scheduleDisableReasonSchema.nullable(),
73+
disabledReason: scheduleDisableReasonSchema.nullable().default(null),
7374
lastFailedAt: z.string().nullable(),
7475
/**
7576
* Legacy rows pre-dating the `sourceType` column can still surface in

‎apps/sim/lib/data-drains/dispatcher.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const DAY_MS = 24 * HOUR_MS
1616
const DISPATCH_PAGE_SIZE = 200
1717

1818
/**
19-
* Cron start times drift, so each cadence's buffer lets the next tick claim a
20-
* drain whose preceding tick started late. The buffer stays well under the
21-
* 15-minute cron tick so a drain is never claimed twice within one interval.
2219
* Cadence is measured from the worker's claim timestamp, independently of
23-
* delivery duration.
20+
* delivery duration. That claim lands after any cron drift and queueing delay,
21+
* so each cadence's buffer lets the next tick still claim a drain whose last
22+
* run started late. The buffer stays well under the 15-minute cron tick so a
23+
* drain is never claimed twice within one interval.
2424
*/
2525
const CADENCE_SCHEDULE: Record<CadenceType, { intervalMs: number; bufferMs: number }> = {
26-
every_15_minutes: { intervalMs: 15 * MINUTE_MS, bufferMs: 2 * MINUTE_MS },
26+
every_15_minutes: { intervalMs: 15 * MINUTE_MS, bufferMs: 7 * MINUTE_MS },
2727
hourly: { intervalMs: HOUR_MS, bufferMs: 5 * MINUTE_MS },
2828
daily: { intervalMs: DAY_MS, bufferMs: 5 * MINUTE_MS },
2929
}

‎apps/sim/lib/data-drains/service.integration.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ describe('data drain durable delivery', () => {
452452
})
453453

454454
it.each([
455-
{ cadence: 'every_15_minutes', ageMs: 13 * 60_000, due: false },
456-
{ cadence: 'every_15_minutes', ageMs: 13 * 60_000 + 1000, due: true },
455+
{ cadence: 'every_15_minutes', ageMs: 8 * 60_000, due: false },
456+
{ cadence: 'every_15_minutes', ageMs: 8 * 60_000 + 1000, due: true },
457457
{ cadence: 'hourly', ageMs: 55 * 60_000, due: false },
458458
{ cadence: 'hourly', ageMs: 55 * 60_000 + 1000, due: true },
459459
{ cadence: 'daily', ageMs: (23 * 60 + 55) * 60_000, due: false },
@@ -480,6 +480,25 @@ describe('data drain durable delivery', () => {
480480
}
481481
)
482482

483+
it('claims a 15-minute drain on the next tick when its run started minutes late', async () => {
484+
const claimedAt = new Date(Date.now() - 5 * 60_000)
485+
await db
486+
.update(dataDrains)
487+
.set({ scheduleCadence: 'every_15_minutes' })
488+
.where(eq(dataDrains.id, drainId))
489+
expect((await dispatchDueDrains(claimedAt)).dispatched).toBe(1)
490+
await vi.waitFor(async () => {
491+
const [run] = await db.select().from(dataDrainRuns).where(eq(dataDrainRuns.drainId, drainId))
492+
expect(run.status).toBe('success')
493+
})
494+
const nextTick = new Date(claimedAt.getTime() + 15 * 60_000)
495+
expect((await dispatchDueDrains(nextTick)).dispatched).toBe(1)
496+
await vi.waitFor(async () => {
497+
const runs = await db.select().from(dataDrainRuns).where(eq(dataDrainRuns.drainId, drainId))
498+
expect(runs.map((run) => run.status)).toEqual(['success', 'success'])
499+
})
500+
})
501+
483502
it('claims a due drain once when dispatchers race', async () => {
484503
await seedRows(1)
485504
const now = new Date()

0 commit comments

Comments
 (0)