Skip to content

Commit 985e12e

Browse files
authored
docs: clarify Deno.cron runtime vs Deploy on cron reference (#3106)
Co-authored-by: lunadogbot <lunadogbot@users.noreply.github.com>
1 parent d125de4 commit 985e12e

4 files changed

Lines changed: 86 additions & 2 deletions

File tree

deploy/reference/cron.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Cron jobs are scheduled tasks that run automatically on a defined schedule. You
88
define cron jobs in your code using the `Deno.cron()` API, deploy your
99
application, and the platform discovers and runs them on schedule.
1010

11+
[`Deno.cron()`](/runtime/fundamentals/cron/) is a Deno runtime API — it ships
12+
with Deno itself. Deno Deploy builds on top of that runtime API: it discovers
13+
your `Deno.cron()` definitions at deployment time, schedules and invokes them,
14+
handles retries, and surfaces runs in the dashboard and logs, so you don't need
15+
to keep a long-running process up yourself.
16+
1117
## Defining cron jobs in code
1218

1319
`Deno.cron()` takes a human-readable name, a schedule, and a handler function.

runtime/_data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export const sidebar = [
8383
title: "OpenTelemetry",
8484
href: "/runtime/fundamentals/open_telemetry/",
8585
},
86+
{
87+
title: "Cron",
88+
href: "/runtime/fundamentals/cron/",
89+
},
8690
{
8791
title: "Stability and releases",
8892
href: "/runtime/fundamentals/stability_and_releases/",

runtime/fundamentals/cron.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
last_modified: 2026-05-13
3+
title: "Cron"
4+
description: "Schedule recurring tasks in Deno with the Deno.cron() runtime API, an unstable feature enabled via --unstable-cron."
5+
---
6+
7+
[`Deno.cron()`](/api/deno/~/Deno.cron) is a Deno runtime API for scheduling
8+
JavaScript or TypeScript code to run on a recurring schedule, expressed using
9+
[cron syntax](https://en.wikipedia.org/wiki/Cron#UNIX-like). It ships with Deno
10+
itself, so the same code that runs locally can be deployed without changes.
11+
12+
[`Deno.cron`](/api/deno/~/Deno.cron) is currently an unstable API. To use it
13+
locally with `deno run`, enable the
14+
[`--unstable-cron`](/runtime/reference/cli/unstable_flags/#--unstable-cron) flag
15+
(or add `"cron"` to the
16+
[`unstable`](/runtime/fundamentals/configuration/#unstable-features) array in
17+
`deno.json`).
18+
19+
```sh
20+
deno run --unstable-cron main.ts
21+
```
22+
23+
<a href="/api/deno/~/Deno.cron" class="docs-cta runtime-cta">Deno.cron API
24+
reference</a>
25+
26+
## Defining a cron job
27+
28+
[`Deno.cron()`](/api/deno/~/Deno.cron) takes a human-readable name, a schedule,
29+
and a handler function. The name identifies the cron job in logs, the schedule
30+
determines when the handler fires, and all times are in UTC.
31+
32+
```ts
33+
Deno.cron("log-a-message", "* * * * *", () => {
34+
console.log("This runs once a minute.");
35+
});
36+
```
37+
38+
The schedule can be a standard 5-field cron expression or a structured object:
39+
40+
```ts
41+
Deno.cron("hourly-task", { hour: { every: 1 } }, () => {
42+
console.log("This runs once an hour.");
43+
});
44+
```
45+
46+
Cron jobs must be registered at the top level of a module, before any server
47+
starts. Definitions nested inside request handlers, conditionals, or callbacks
48+
will not be picked up.
49+
50+
## Retries and backoff
51+
52+
By default, failed handler invocations are not retried. Pass a `backoffSchedule`
53+
(an array of millisecond delays) to retry on failure:
54+
55+
```ts
56+
Deno.cron(
57+
"retry-example",
58+
"* * * * *",
59+
{ backoffSchedule: [1000, 5000, 10000] },
60+
() => {
61+
throw new Error("Will be retried up to three times.");
62+
},
63+
);
64+
```
65+
66+
## Running cron jobs in production
67+
68+
[`Deno.cron`](/api/deno/~/Deno.cron) keeps execution state in-memory in the Deno
69+
CLI, which means each process maintains its own independent set of cron tasks.
70+
For production workloads, [Deno Deploy](/deploy/reference/cron/) builds on top
71+
of this runtime API: it discovers your [`Deno.cron()`](/api/deno/~/Deno.cron)
72+
definitions at deployment time, schedules and invokes them, handles retries, and
73+
surfaces runs in a dashboard — so you don't need to keep a long-running process
74+
up yourself.

runtime/reference/cli/unstable_flags.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ new Worker(`data:application/javascript;base64,${btoa(`postMessage("ok");`)}`, {
196196

197197
## `--unstable-cron`
198198

199-
Enabling this flag makes the [`Deno.cron`](/deploy/kv/manual/cron) API available
200-
on the `Deno` namespace.
199+
Enabling this flag makes the [`Deno.cron`](/runtime/fundamentals/cron/) API
200+
available on the `Deno` namespace.
201201

202202
## `--unstable-kv`
203203

0 commit comments

Comments
 (0)