Schedules
A schedule is a reusable, named definition of when work should run, never what. It can observe a cron expression or a typed event, then be attached to a sync, pipeline, or workflow.
Defining a schedule
Build one with defineSchedule(id). Use .cron(...) for time or .on(events.*) for an event. It
returns an inert ScheduleDefinition that does nothing until something references it.
// schedules/erp.ts
import { defineSchedule } from "@sixb/core"
export const hourlyErpSync = defineSchedule("hourly-erp-sync").cron("0 * * * *", {
timezone: "Europe/Paris",
})
| Method | Signature | Notes |
|---|---|---|
.cron(expression, options?) | expression: string, options?: { timezone?: string } | timezone is validated against Intl.DateTimeFormat; an invalid zone throws |
.on(selector) | A terminal events.* selector | Creates a typed event schedule |
The id must be unique and non-empty. An invalid cron expression or timezone throws at
definition time, so a malformed schedule fails fast rather than silently never firing.
Attaching with .when(...)
A schedule drives work only when a sync, pipeline, or workflow references it through
.when(...). Pass the schedule definition itself:
// syncs/erp.ts
import { defineSync } from "@sixb/core"
import { acmeErpConnector } from "../connectors/acme-erp"
import { erpInvoicesDataset } from "../datasets/erp"
import { hourlyErpSync } from "../schedules/erp"
export const syncErpInvoices = defineSync("sync-erp-invoices")
.when(hourlyErpSync)
.from(acmeErpConnector)
.read((client) => client.listInvoices())
.intoDataset(erpInvoicesDataset)
Every .when(...) receives a named schedule definition. Multiple schedules on the same target use
OR semantics: any one can request a run.
Cron dialect
Sixb uses a 5-field cron expression: minute hour day-of-month month day-of-week.
| Field | Range | Notes |
|---|---|---|
| minute | 0–59 | |
| hour | 0–23 | |
| day-of-month | 1–31 | |
| month | 1–12 | |
| day-of-week | 0–6 | 0 = Sunday; 7 is normalized to 0 |
Each field supports * (any), lists (1,15), ranges (9-17), and steps (*/5, 0-30/10).
When both day-of-month and day-of-week are restricted (neither is *), a tick matches if
either one matches (standard cron OR semantics); otherwise both must match.
0 8 * * * every day at 08:00
*/5 * * * * every 5 minutes
0 9-17 * * 1-5 every hour, 09:00–17:00, Mon–Fri
0 0 1 * * midnight on the 1st of each month
Timezone
Pass an IANA zone to .cron(...) (e.g. "Europe/Paris", "America/New_York") when a schedule
must fire relative to a specific wall clock — say, an invoice rollup that runs at local
midnight. Without it, the expression is evaluated against the host machine's local time.
Discovery
createSixb() auto-discovers exported ScheduleDefinitions from the schedules/ folder. A
schedule takes effect only through the sync, pipeline, or workflow that references it with
.when(...).
my-project/
schedules/
erp.ts # defineSchedule(...).cron(...)
invoices.ts # defineSchedule(...).on(events.*)
Related
- Syncs — pull external data on a schedule
- Pipelines — transform datasets on a schedule
- Workflows — run multi-step processes on a schedule
- Event schedules — react to typed domain events
- Project structure — the full folder layout