Skip to content

Commit 47c290f

Browse files
durable-workflow.github.io: update v2 changes
1 parent 2186004 commit 47c290f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

docs/features/schedules.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The `scheduleId` is a unique, user-chosen identifier for the schedule. Each trig
4343
| `labels` | `array` | `[]` | Visibility labels applied to each triggered run |
4444
| `memo` | `array` | `[]` | Memo fields applied to each triggered run |
4545
| `searchAttributes` | `array` | `[]` | Search attributes applied to each triggered run |
46-
| `jitterSeconds` | `int` | `0` | Reserved for future random jitter support |
46+
| `jitterSeconds` | `int` | `0` | Maximum random delay in seconds added to each fire time (thundering-herd mitigation) |
4747
| `maxRuns` | `int\|null` | `null` | Maximum number of runs before auto-deleting the schedule |
4848
| `connection` | `string\|null` | `null` | Queue connection for triggered runs (overrides the workflow class default) |
4949
| `queue` | `string\|null` | `null` | Queue name for triggered runs (overrides the workflow class default) |
@@ -214,6 +214,25 @@ $schedule = ScheduleManager::create(
214214

215215
The routing precedence is: schedule fields → workflow class defaults → global queue config.
216216

217+
## Jitter
218+
219+
When multiple schedules share the same cron expression, they all fire at the exact same instant, creating a thundering-herd spike. The `jitterSeconds` parameter spreads triggers across a random window to smooth the load.
220+
221+
```php
222+
$schedule = ScheduleManager::create(
223+
scheduleId: 'hourly-report',
224+
workflowClass: ReportWorkflow::class,
225+
cronExpression: '0 * * * *',
226+
jitterSeconds: 300, // fire within 0–300 seconds after the top of the hour
227+
);
228+
```
229+
230+
When `jitterSeconds` is set, each computed `next_fire_at` is offset by a random value between 0 and `jitterSeconds` (inclusive). The jitter is re-rolled every time the next fire time is calculated — after a trigger, after a resume, or after an update.
231+
232+
Jitter applies only to the tick-evaluation fire time stored in the database. Backfill enumeration always uses canonical (unjittered) cron times so that backfilled occurrences land on exact cron boundaries.
233+
234+
Setting `jitterSeconds` to `0` (the default) disables jitter entirely — fire times are exact cron matches.
235+
217236
## History event types
218237

219238
When a schedule triggers a workflow, a `ScheduleTriggered` history event is recorded on the started workflow run. This provides lineage from the schedule to the workflow:

0 commit comments

Comments
 (0)