Schedule tasks
Create task runs from one-time, interval, or cron schedules.
Use a task-colocated schedule when Runlane should create runs at known times without an application request calling trigger().
Add a schedule to the task
Put the schedule beside its task definition. For example, create src/tasks/generate-daily-report.ts:
import { task } from '@runlane/core'
import * as z from 'zod'
const env = z.object({ REPORTS_API_URL: z.url() }).parse(process.env)
export const generateDailyReport = task({
id: 'report.generate-daily',
schema: z.object({ accountId: z.string() }),
schedule: {
id: 'report.daily.account-123',
every: '24h',
startsAt: new Date('2026-01-01T09:00:00.000Z'),
payload: { accountId: 'account-123' },
},
async run({ accountId }, context) {
const response = await fetch(new URL(`/accounts/${encodeURIComponent(accountId)}/daily`, env.REPORTS_API_URL), {
method: 'POST',
signal: context.signal,
})
if (!response.ok) throw new Error(`Reports API returned ${response.status}`)
},
})This task uses 24-hour boundaries from the given start time. See when a schedule starts for which fires it owes.
Register the task in createRunlane({ tasks }). Schedule ids must be unique inside the runtime. Registration validates and transforms the schedule payload synchronously through the task schema. Due occurrences use that normalized payload without applying the input schema again.
A schedule accepts one cadence: runAt for one occurrence, every for a fixed interval, or cron for cron-based occurrences. Do not mix cadence fields in one schedule. See schedule forms for the default interval origin.
Let maintenance create due runs
Maintenance discovers code-declared schedules and arms their next fires. Runtime writes and activation can also arm fires directly. If you run bounded maintenance, call it from the scheduled job or command that owns maintenance:
import { type RunlaneRuntime } from '@runlane/core'
export async function materializeDueSchedules(runlane: RunlaneRuntime) {
const maintenance = await runlane.createMaintenanceHandler({ scheduleLookahead: '1m' })()
return maintenance.materialized.map((item) => item.run.id)
}Invoke this handler once per minute. It returns the run IDs created by that pass. Set scheduleLookahead to the invocation interval. The default is contractDefaults.maintenance.scheduleLookahead (1m). Maintenance arms the next fire inside that window without creating its run early.
At the fire time, Runlane reads the current schedule and creates the run with its current payload, queue, and keys. A transport that supports delayed delivery gets a schedule wakeup hint. Future fires on other transport lanes need a due maintenance pass or continuously running service timers. An owed fire already due when written gets an immediate wakeup on any transport lane. Polling workers read armed fires from storage. A polling delivery handler starts fires only before its handoff time. Delivery and queue capacity can still delay the handler start.
A wakeup hint does not use the outbox. Once created, the run uses ordinary dispatch and its durable delivery outbox. Keep MaintenancePhase.OutboxFlush enabled to recover pending run deliveries. Maintenance does not execute task handlers; keep a worker or transport consumer available.
Overlapping maintenance passes and duplicate hints share storage-owned occurrence acceptance. Losing a hint leaves the armed fire available to a later maintenance pass. Updates, pauses, and deletion before acceptance affect the pending fire. Runs already accepted keep their saved payload and execution policy. Declared fires use the executing deployment's current task catalog and saved active override.
Schedules inherit the task's singletonKey. If the key is held when a fire is accepted, that fire is skipped permanently. Finishing the earlier run allows the next fire to proceed. Each singleton skip emits schedule_fire_skipped with schedule_id, fire_at (ISO 8601), and reason: singleton_key, and increments runlane.schedule.conflict.count for materialize. Maintenance returns these skips in scheduleFiresSkipped, beside materialized; each entry has scheduleId, fireAt, and reason.
To verify the setup, use a one-time schedule with a due runAt in an isolated environment. Run one maintenance pass and confirm maintenance.materialized contains its schedule id. Then run a drain worker and confirm the new run succeeds.
If no run appears, check the task registration, schedule state, due time, runtime clock, and environment.
If the run is queued but does not execute, fix the worker or delivery path. Adding another schedule will create another source of work.
Assign maintenance ownership before deploying schedules.
Save customer-created schedules
Use the runtime API when an application request creates or changes a schedule. With generateDailyReport registered in your runtime:
const schedule = await runlane.schedules.create(generateDailyReport, {
cron: '0 9 * * 1-5',
timeZone: 'America/New_York',
payload: { accountId: 'account-456' },
externalId: 'account-456',
deduplicationKey: 'account-456.weekday-report',
})
await runlane.schedules.deactivate(schedule.id)
await runlane.schedules.activate(schedule.id)The returned source is runtime; declarations return declared. The payload follows the task's input type. Repeating an identical keyed create returns the existing schedule. Use update with the complete replacement definition when changing it.
create, update, and activate arm a pending fire in the same 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. Accepting a fire arms the next one within the same window, so a schedule faster than your maintenance timer keeps running on time. Eligible fires follow the schedule start rule. Resuming a cron or interval schedule with activate skips fires that came due while it was paused. A once schedule that has not run yet still runs when activated after its time. Because update defaults active to true, updating a paused schedule resumes it the same way. They publish a best-effort wakeup after commit. A failed hint does not fail the write; keep maintenance enabled for recovery and fires outside that window.
An explicit queue targets the queue by name. Runs use its current registered policy, including concurrency. If omitted, they use the task's current queue. A process missing the explicit queue leaves the fire for another process. Maintenance logs schedule_queue_missing at most once a minute per queue.
Runtime definitions survive deployment. Keep their task schemas compatible with the normalized payloads already stored. When its catalog lacks a referenced task, maintenance logs schedule_task_missing at most once a minute per task and leaves the fire for a process that has the task.
For a declared schedule, use the same activation methods with its declared ID. The saved override wins over enabled and survives restarts. Edit code to update or remove the definition. Do not use the reserved runtime_schedule_ prefix for declaration IDs.
After removing a declaration, keep its task registered until a due scan disarms its pending fire. A process leaves records for tasks outside its catalog alone. Stop older deployments that still declare the schedule.
Read the schedule API reference for pagination, timing, and deletion behavior.