new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Deno · Fundamentals · all subjects

cron

13 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Cron schedule structured object format

Cron schedules can be defined using a structured object with fields like { hour: { every: 1 } } as an alternative to string expressions.

Cron jobs must be registered at top level

Cron jobs must be registered at the top level of a module, before any server starts. Definitions nested inside request handlers, conditionals, or callbacks will not be picked up.

Deno.cron() basic usage

Deno.cron() is a runtime API for scheduling JavaScript or TypeScript code to run on a recurring schedule using cron syntax. It takes a human-readable name, a schedule (as a 5-field cron expression or structured object), and a handler function. All times are in UTC.

Deno.cron() is unstable, requires --unstable-cron flag

Deno.cron() is currently an unstable API. To use it locally with deno run, enable the --unstable-cron flag or add "cron" to the unstable array in deno.json.

Cron expression format: 5 fields

A cron expression consists of 5 fields separated by spaces: minute (0-59), hour (0-23), day of month (1-31), month (1-12 or JAN-DEC), and day of week (0-6 or SUN-SAT, where 0 is Sunday). Each field can be an exact value, * (every value), a range (1-5), a list (1,3,5), or a step (*/15).

Cron job retry with backoffSchedule

By default, failed handler invocations are not retried. To enable retries, pass a backoffSchedule parameter as an array of millisecond delays. For example, backoffSchedule: [1000, 5000, 10000] retries up to three times with those delays.

Deno.cron() basic example

Example of a simple cron job: Deno.cron("log-a-message", "* * * * *", () => { console.log("This runs once a minute."); });

Deno.cron() with backoff example

Example with retry configuration: Deno.cron("retry-example", "* * * * *", { backoffSchedule: [1000, 5000, 10000] }, () => { throw new Error("Will be retried up to three times."); });

Deno.cron() execution in CLI vs production

Deno.cron() keeps execution state in-memory in the Deno CLI, so each process maintains its own independent set of cron tasks. For production workloads, Deno Deploy discovers cron definitions at deployment time, schedules and invokes them, handles retries, and surfaces runs in a dashboard.

Deno.cron() with OpenTelemetry

When OpenTelemetry is enabled (OTEL_DENO=true), each Deno.cron() invocation automatically produces an OpenTelemetry span. Each cron invocation creates a span named after the cron job, covering the handler function duration, with any spans created inside nested as children.

Run deno with --unstable-cron flag

Command to run a Deno script with cron support: deno run --unstable-cron main.ts

Enable OpenTelemetry with cron

Command to run Deno with both OpenTelemetry and cron support: OTEL_DENO=true deno run --unstable-cron main.ts

Deno.cron() example with structured schedule

Example with structured object schedule: Deno.cron("hourly-task", { hour: { every: 1 } }, () => { console.log("This runs once an hour."); });

Give your agent this brain