Schedules
Create runtime schedules and control code-owned declarations.
Use runlane.schedules from a runtime returned by createRunlane(). A schedule creates ordinary task runs when its fire time arrives. It does not execute a handler itself.
Create and replace runtime schedules
const schedule = await runlane.schedules.create(sendEmail, {
cron: '0 9 * * 1-5',
timeZone: 'America/New_York',
payload: { userId: 'user-123' },
externalId: 'weekday-mail',
deduplicationKey: 'user-123.weekday-mail',
})
await runlane.schedules.update(schedule.id, sendEmail, {
every: '24h',
payload: { userId: 'user-123' },
deduplicationKey: 'user-123.weekday-mail',
})sendEmail is your registered task definition. Both methods accept ScheduleWrite<TInput>. TInput comes from the task's input schema. payload is required unless that schema accepts undefined. Runlane validates and transforms it once at create or update; maintenance and later attempts reuse the normalized value. Async input schemas are supported for runtime writes.
| Field | Behavior |
|---|---|
cron, timeZone? | Cron expression and optional IANA time zone. The runtime default is contractDefaults.schedules.timeZone. |
every, startsAt?, endsAt? | Positive duration and optional inclusive interval bounds. Without startsAt, boundaries begin at the Unix epoch. Equal start/end times permit one boundary. |
runAt | Valid Date for a single occurrence, including a past time. |
queue? | Registered QueueDefinition. Fires and reads resolve its name to the current registered policy, and a repeated keyed create compares the name only. Omission uses the task's current queue. |
active? | Effective runtime state; defaults to true. |
externalId? | Nonempty, nonunique application label. |
deduplicationKey? | Nonempty environment-scoped key for one runtime definition. |
Choose exactly one cadence: cron, every, or runAt. The ScheduleTiming type is derived from scheduleWriteSchema. Parsed outputs include a type tag (cron, interval, or once); write inputs do not accept this tag. timeZone requires cron; startsAt and endsAt require every. Supply dates as Date instances to the API. The CLI accepts ISO date strings.
update(id, task, options) replaces the full definition, including payload, labels, key, queue, and active state. Omitted optional fields are cleared or take their normal defaults. The revision increases internally; callers cannot choose it.
Concurrent creates with the same deduplication key and identical normalized definitions return the existing schedule. A different definition throws schedule_conflict; use update to replace it. Updating a key claims the new key and releases the old one atomically. External IDs do not prevent duplicates.
Read and control schedules
| Method | Result |
|---|---|
get(id) | ScheduleRecord, or undefined when absent from storage and the local catalog. |
list({ taskId?, externalId?, cursor?, limit? }) | Page<ScheduleSummary> with data and optional nextCursor. Summaries omit payload. |
activate(id) | Effective record after persisting active state. |
deactivate(id) | Effective record after blocking new occurrence acceptance. |
delete(id) | Hides a runtime definition and releases its deduplication key. Returns no value. |
IDs, task filters, external IDs, and deduplication keys accept plain strings under the storable string rule. Records return branded identifiers. Invalid definitions and unsupported declared mutations throw configuration_invalid. Payload failures throw validation_failed.
Records contain source, id, taskId, optional queue, cadence fields, normalized payload, and effective active. Runtime records also contain createdAt, updatedAt, revision, optional nextFireAt, and any supplied label/key. Declared records have no stored creation time or runtime revision.
Lists return local declarations first, ordered by schedule ID. Runtime definitions follow in (createdAt,id) order. The opaque cursor records its source and position. Keep the environment and filters unchanged while paging. A filtered page can be empty and still have nextCursor; continue until it is absent. Each runtime page uses a bounded index query. Deleted definitions never appear in ordinary reads.
delete throws the existing missing-schedule error for an unknown ID. Repeating deletion succeeds while the deletion marker exists. After maintenance removes that marker, the ID is unknown. Cleanup removes the definition marker and its one occurrence record together. Accepted runs keep their payload and execution policy after a schedule changes.
Updates, pauses, and deletion take effect when the fire is accepted. Future fires have no run and hold no singleton key. Resuming a paused cron or interval schedule skips fires that came due while it was paused and allows the next fire. A once schedule that has not run yet still runs when activated after its time. An update that sets a paused schedule active again resumes it the same way. A completed or skipped fire stays done.
Code-owned declarations
Task-colocated schedule declarations keep their existing syntax and registration behavior. Only schedules.create() writes a runtime definition. No startup synchronization or extra runtime option is required.
activate and deactivate on a locally registered declaration save a persistent override. The override wins over declared enabled, survives deployment, and applies again if the same schedule ID returns. update rejects with "Declared schedules are code-owned; edit the declaration to update it." delete rejects with "Declared schedules are code-owned; remove the declaration to delete it."
A process sees only declarations in its own catalog. It cannot read or control an absent declaration, and does not infer global removal. Due scans leave records for tasks outside the local catalog intact. If the task is registered but no longer declares the schedule ID, a due scan disarms its pending fire without creating a run. The record keeps its last processed fire, so re-adding the schedule cannot replay it. Removing a task entirely does not clean up its declarations. Scans continue past fires this process cannot run within a bounded scan. At a fire time, the executing deployment reads its current declaration and the saved active override. Stop older deployments before relying on a removed declaration to stop firing. The runtime_schedule_ prefix is reserved for generated runtime IDs; registration rejects declared IDs using it.
When a schedule starts
Cron and interval schedules owe only fires at or after they start existing. A runtime schedule starts at its creation write. A declared schedule starts when Runlane first discovers it without an occurrence record. A boundary exactly at that moment is owed; earlier boundaries are skipped. For example, an hourly cron created at 10:59:30 first runs for 11:00, not 10:00. Missed fires after that moment still coalesce to the latest boundary. Once schedules are unchanged: an unprocessed past runAt still runs. Updates to existing schedules, including cadence changes, and pause/resume keep their existing behavior.
Timing and recovery
An occurrence's fire time sets when its run becomes eligible, not when its handler is guaranteed to start. Storage prevents accepting a fire before that time. Maintenance, delivery, queue admission, and available workers determine when execution can start afterward. See eligibility and start time.
scheduleLookahead defaults to contractDefaults.maintenance.scheduleLookahead (1m). It sets how far ahead maintenance arms wakeups. Set it to your maintenance interval, or false to discover only due fires. Arming writes one pending occurrence record. It creates no run. At the fire time, Runlane reads the current payload, queue, cadence, and task keys before creating the run.
create and update also arm the pending fire in their write transaction when it falls within the arming window. On a polling lane, any next fire is armed. On a transport lane, the window reaches as far as the queue can delay a wakeup, and at least contractDefaults.maintenance.scheduleLookahead, including an owed fire already due. Outside a maintenance pass, accepting a fire arms the next one within the same window, except for the default SQS Lambda policy. See Lambda schedules and maintenance cadence when schedules fire faster than maintenance. activate on a paused cron or interval schedule records the latest fire that came due while paused as skipped and arms the next fire within that window. Activation covers locally declared schedules too. An inactive schedule or a fire beyond that window keeps any existing armed fire with fresh routing; it is checked at fire time. Pause keeps the pending fire, which is skipped when due.
After commit, writes publish a best-effort wakeup. A due fire gets an immediate hint on every transport lane; no delay support is required. Publish failure logs schedule_wakeup_publish_failed and does not fail the saved write. Future hints follow the delay rule below.
If the transport advertises enough delayed-delivery capacity for the queue, arming also publishes a schedule_wakeup hint with availableAt equal to the fire time. The hint bypasses the run-owned outbox. A failed or lost hint cannot erase the pending fire: maintenance, polling workers, and service timers recover it from storage. A hint for a fire that an update moved or removed runs whichever fire is armed instead. An armed fire that the current definition no longer produces is replaced by the next fire the schedule still owes; it never counts as processed. Without delayed delivery, future fires on transport lanes need a due maintenance pass or service timer. See scheduled polling workers for when a polling handler can start a fire.
Both schedule sources use run_${occurrenceId} as the deterministic run ID. The occurrence record keeps lastProcessedAt separately from the pending fire. Only accepting or skipping a fire advances it. Arming may replace a pending fire with an earlier or later one after that boundary. Fires at or before it cannot replay, even after the run is pruned. A late pass coalesces undiscovered ticks owed since the schedule started to the latest eligible boundary; an already armed fire can run late once. A once schedule has one fire identity. An owed final interval fire can run after endsAt.
Schedules inherit the task's singletonKey. If another active run holds the key at fire time, Runlane completes the fire as skipped. It does not retry that fire after the key becomes free. The next eligible fire can run normally.
Cron schedules follow Vixie daylight-saving rules. A fixed time skipped by a spring clock change runs at the first valid time after the gap, on the same day. If the gap ends at midnight, no valid time is left that day, so that day has no run. For example, in America/Nuuk clocks moved from 23:00 to midnight on March 28, 2026, so 30 23 * * * did not run that day and ran again at 23:30 on March 29. A fixed time runs once during an autumn repeat, at its first occurrence. Lists and ranges of fixed times follow these rules too. Crons with * or steps in the seconds, minute, or hour fields follow the clock: they skip missing times and run through both occurrences of a repeated hour. A schedule whose fire time cannot be computed logs schedule_fire_failed and is skipped for that pass; other schedules continue. Cron boundaries discard incidental milliseconds; explicit interval origins preserve them.
A schedule targets its explicit queue by name, or the task's current queue when omitted. New runs use the registered queue policy at fire time, so changing concurrency does not invalidate a saved schedule. Maintenance needs the schedule's task and queue registered. A missing queue emits schedule_queue_missing at most once a minute per queue and leaves the fire for a process that can route it. A missing registration emits schedule_task_missing at most once a minute per task, leaves the fire for a process that has the task, and continues bounded discovery. It does not change the definition's timing. Acceptance completes or skips the fire, advances runtime nextFireAt, and arms a nearby following fire in the same transaction as run creation. Stored payloads are never transformed again after a revision conflict.
A write fails when the task's concurrencyKey needs a bounded queue and the schedule's queue has no concurrency; declared schedules fail the same way at registration. If a fire's run still cannot be created later, for example because a changed key callback throws for the stored payload, Runlane logs schedule_fire_failed and keeps the fire armed. Other schedules, maintenance passes, and delivery drains continue.
See schedule tasks for setup and run maintenance for deployment ownership.