Skip to main content

@rtorcato/cf-common

Type Aliases​

ScheduledJob​

ScheduledJob<Env> = (controller, env, ctx) => void | Promise<void>

Defined in: index.ts:4

A single scheduled job. controller.cron/.scheduledTime tell you which fired and when.

Type Parameters​

Env​

Env

Parameters​

controller​

ScheduledController

env​

Env

ctx​

ExecutionContext

Returns​

void | Promise<void>

Functions​

defineScheduled()​

defineScheduled<Env>(jobs): (controller, env, ctx) => Promise<void>

Defined in: index.ts:26

Build a scheduled handler that routes each cron expression to a named job, so one Worker with several triggers stays a flat map instead of an if (cron === …) ladder. Keys must match the crons in wrangler.jsonc.

Throws a CloudflareError if a trigger fires with no matching job — a misconfiguration worth surfacing in logs, not swallowing.

Example​

export default {
scheduled: defineScheduled({
'0 * * * *': async (_c, env) => rollupHourly(env),
'0 0 * * *': async (_c, env) => rollupDaily(env),
}),
}

Type Parameters​

Env​

Env = unknown

Parameters​

jobs​

Record<string, ScheduledJob<Env>>

Returns​

(controller, env, ctx) => Promise<void>