mvp-ai's picture
|
download
raw
6.38 kB

Scheduled runs

A build often needs to run on a clock — a nightly integration suite, a weekday-morning report, a periodic cache warm. Zuke lets you declare that schedule in the build, in the timezone you think in, as part of the CI pipeline generated by cicd(). You delete the external Cloud-Scheduler-plus-webhook dance and keep the schedule in code, under review, next to everything else it triggers.

import { Build, cicd, run, target } from "@zuke/core";

class Nightly extends Build {
  ci = cicd({
    provider: "github",
    pipeline: {
      triggers: {
        push: ["main"],
        // Weekday mornings and afternoons, Sofia local time.
        schedule: [{ cron: "30 9,13,15 * * 1-4", tz: "Europe/Sofia" }],
      },
    },
  });

  report = target().executes(() => generateReport());
}

await run(Nightly);

The schedule entry

triggers.schedule is an array of entries; each is a 5-field cron in an optional IANA timezone:

interface ScheduleEntry {
  cron: string; // "minute hour day-of-month month day-of-week"
  tz?: string; // an IANA zone, e.g. "Europe/Sofia"; omitted (or "UTC") = already UTC
}

The cron is a standard 5-field expression. The tz is the zone the cron is written in — so { cron: "30 9 * * 1-5", tz: "Europe/Sofia" } means "09:30 Sofia time, Monday to Friday", regardless of what that is in UTC on any given day. Omit tz (or pass "UTC") and the cron is treated as already-UTC and emitted verbatim.

What Zuke compiles it to

GitHub Actions (and Azure Pipelines) only understand UTC cron. So a tz entry is compiled to the UTC cron(s) that fire at the intended local wall-clock time. There are two cases:

  • A fixed-offset zone (or plain UTC) needs a single cron and no guard — the hours are shifted by the constant offset once and emitted.
  • A daylight-saving zone uses more than one UTC offset across the year, so it compiles to one UTC cron per distinct offset — typically two, a winter one and a summer one. Both are registered, because at any moment only one is the correct offset. To stop the other one from firing at the wrong local time, Zuke also generates a wall-clock guard (see below).

For example, 30 9 * * 1-5 in Europe/Sofia (UTC+2 in winter, UTC+3 in summer) compiles to two crons — 30 7 * * 1-5 and 30 6 * * 1-5 — one of which fires at 09:30 Sofia in each half of the year.

Offsets are sampled from a pinned reference year, and every day of that year is checked (not just January and July), so a sub-seasonal window — e.g. a Ramadan-based change like Africa/Casablanca — is caught. Because the year is pinned, the generated YAML is deterministic: it never churns as the calendar advances, so a generate-ci --check gate stays stable.

The DST wall-clock guard

When a schedule targets a daylight-saving zone, both offsets' UTC crons are live, but only one is correct at a time. Zuke inserts a guard so the wrong one is skipped:

  • A generated job zuke-schedule-guard runs a small shell step that reads the current wall-clock in the schedule's zone and checks it against the declared local firing time (minute, hour, and any day/month fields).
  • Every other job in the pipeline gains a dependency on the guard and runs only when it cleared this firing. On a non-schedule event (a push, a pull request, a manual dispatch) the guard always lets the run through — it only filters scheduled firings.

The net effect: the "wrong" offset's cron still fires half the year, but its jobs are gated off, so your schedule runs at the right local time all year with no manual DST bookkeeping.

Fall-back day caveat. On the once-a-year DST fall-back day the ambiguous hour occurs twice, and both offsets' crons satisfy the wall-clock guard — so a schedule inside that one hour can fire twice that day. This is the standard cron guidance restated: make scheduled work idempotent rather than assuming exactly-once.

The supported grammar

The cron grammar is a deliberate subset — enough for real schedules, small enough to shift and guard correctly:

  • Fields: numeric minute, hour, day-of-month, month, and day-of-week — single values (9), comma lists (9,13,15), ranges (1-5), and slash steps (*/15, 9/4). Day-of-week is 0-7 with both 0 and 7 meaning Sunday.
  • Timezone: must have a whole-hour UTC offset.

Anything outside that raises a friendly error telling you to write the UTC cron directly (and drop the tz):

  • named fields (MON, JAN) or hashes,
  • a fractional-hour zone (e.g. Asia/Kolkata at UTC+5:30),
  • a day-constrained schedule that would cross midnight once shifted to UTC — which can't be expressed as a single cron without moving the day field too.

The escape hatch is always the same: express the schedule as a plain UTC cron yourself and omit tz.

Provider support

Support mirrors each platform's capability:

Provider Behaviour
GitHub Full treatment — UTC crons plus the DST guard job.
Azure Native schedules: for UTC or fixed-offset zones. A DST zone errors — the guard is GitHub-only; write the cron in UTC for Azure.
GitLab Ignored — GitLab schedules are configured in the project's web UI, not in-file.
Bitbucket Ignored — same reason; configure schedules in the Bitbucket UI.

Reference

Xet Storage Details

Size:
6.38 kB
·
Xet hash:
bd5467ce92c7c11d2109c31f94923d4f5e15871c97da921f85fb618ea08b8ca5

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.