Docs

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.

TS
// schedules/erp.ts
import { defineSchedule } from "@sixb/core"

export const hourlyErpSync = defineSchedule("hourly-erp-sync").cron("0 * * * *", {
  timezone: "Europe/Paris",
})
MethodSignatureNotes
.cron(expression, options?)expression: string, options?: { timezone?: string }timezone is validated against Intl.DateTimeFormat; an invalid zone throws
.on(selector)A terminal events.* selectorCreates 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:

TS
// 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.

FieldRangeNotes
minute0–59
hour0–23
day-of-month1–31
month1–12
day-of-week0–60 = 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.

TXT
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(...).

TXT
my-project/
  schedules/
    erp.ts       # defineSchedule(...).cron(...)
    invoices.ts  # defineSchedule(...).on(events.*)

Search docs

Search the documentation