Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/docs/content/docs/platform/enterprise/data-drains.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ The detail page shows the last ten runs with status, trigger, time, row count, b

## Cadence and latency

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:
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:

| Cadence | Runs when the last run started at least |
| --- | --- |
| **Every 15 minutes** | 13 minutes ago |
| **Every 15 minutes** | 8 minutes ago |
| **Every hour** | 55 minutes ago |
| **Every day** | 23 hours 55 minutes ago |

Expand Down
5 changes: 3 additions & 2 deletions apps/sim/lib/api/contracts/schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export const workflowScheduleRowSchema = z.object({
status: scheduleStatusSchema,
/**
* Why Sim turned the schedule off. Null while it is active or completed, and
* when a person disabled it.
* when a person disabled it. Defaulted so a new client tolerates an old
* server's response during rollout.
*/
disabledReason: scheduleDisableReasonSchema.nullable(),
disabledReason: scheduleDisableReasonSchema.nullable().default(null),
lastFailedAt: z.string().nullable(),
/**
* Legacy rows pre-dating the `sourceType` column can still surface in
Expand Down
10 changes: 5 additions & 5 deletions apps/sim/lib/data-drains/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const DAY_MS = 24 * HOUR_MS
const DISPATCH_PAGE_SIZE = 200

/**
* Cron start times drift, so each cadence's buffer lets the next tick claim a
* drain whose preceding tick started late. The buffer stays well under the
* 15-minute cron tick so a drain is never claimed twice within one interval.
* Cadence is measured from the worker's claim timestamp, independently of
* delivery duration.
* delivery duration. That claim lands after any cron drift and queueing delay,
* so each cadence's buffer lets the next tick still claim a drain whose last
* run started late. The buffer stays well under the 15-minute cron tick so a
* drain is never claimed twice within one interval.
*/
const CADENCE_SCHEDULE: Record<CadenceType, { intervalMs: number; bufferMs: number }> = {
every_15_minutes: { intervalMs: 15 * MINUTE_MS, bufferMs: 2 * MINUTE_MS },
every_15_minutes: { intervalMs: 15 * MINUTE_MS, bufferMs: 7 * MINUTE_MS },
hourly: { intervalMs: HOUR_MS, bufferMs: 5 * MINUTE_MS },
daily: { intervalMs: DAY_MS, bufferMs: 5 * MINUTE_MS },
}
Expand Down
23 changes: 21 additions & 2 deletions apps/sim/lib/data-drains/service.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ describe('data drain durable delivery', () => {
})

it.each([
{ cadence: 'every_15_minutes', ageMs: 13 * 60_000, due: false },
{ cadence: 'every_15_minutes', ageMs: 13 * 60_000 + 1000, due: true },
{ cadence: 'every_15_minutes', ageMs: 8 * 60_000, due: false },
{ cadence: 'every_15_minutes', ageMs: 8 * 60_000 + 1000, due: true },
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
{ cadence: 'hourly', ageMs: 55 * 60_000, due: false },
{ cadence: 'hourly', ageMs: 55 * 60_000 + 1000, due: true },
{ cadence: 'daily', ageMs: (23 * 60 + 55) * 60_000, due: false },
Expand All @@ -480,6 +480,25 @@ describe('data drain durable delivery', () => {
}
)

it('claims a 15-minute drain on the next tick when its run started minutes late', async () => {
const claimedAt = new Date(Date.now() - 5 * 60_000)
await db
.update(dataDrains)
.set({ scheduleCadence: 'every_15_minutes' })
.where(eq(dataDrains.id, drainId))
expect((await dispatchDueDrains(claimedAt)).dispatched).toBe(1)
await vi.waitFor(async () => {
const [run] = await db.select().from(dataDrainRuns).where(eq(dataDrainRuns.drainId, drainId))
expect(run.status).toBe('success')
})
const nextTick = new Date(claimedAt.getTime() + 15 * 60_000)
expect((await dispatchDueDrains(nextTick)).dispatched).toBe(1)
await vi.waitFor(async () => {
const runs = await db.select().from(dataDrainRuns).where(eq(dataDrainRuns.drainId, drainId))
expect(runs.map((run) => run.status)).toEqual(['success', 'success'])
})
})

it('claims a due drain once when dispatchers race', async () => {
await seedRows(1)
const now = new Date()
Expand Down
Loading