Skip to content

Commit 0c69911

Browse files
docs: Add examples for scheduled handlers in Cron Triggers documentation (#20637)
* docs: Add examples for scheduled handlers in Cron Triggers documentation * fix: Update Cron Triggers documentation to use TypeScript example component * Reformat --------- Co-authored-by: kodster28 <[email protected]>
1 parent 0f87ca8 commit 0c69911

File tree

3 files changed

+26
-33
lines changed

3 files changed

+26
-33
lines changed

src/content/docs/workers/configuration/cron-triggers.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ head: []
55
description: Enable your Worker to be executed on a schedule.
66
---
77

8-
import { WranglerConfig } from "~/components";
8+
import { Render, WranglerConfig } from "~/components";
99

1010
## Background
1111

@@ -27,7 +27,9 @@ Cron Triggers execute on UTC time.
2727

2828
To respond to a Cron Trigger, you must add a [`"scheduled"` handler](/workers/runtime-apis/handlers/scheduled/) to your Worker.
2929

30-
Refer to the following examples to write your code:
30+
<Render file="cron-trigger-example" />
31+
32+
Refer to the following additional examples to write your code:
3133

3234
- [Setting Cron Triggers](/workers/examples/cron-trigger/)
3335
- [Multiple Cron Triggers](/workers/examples/multiple-cron-triggers/)
@@ -57,8 +59,6 @@ crons = [ "*/3 * * * *", "0 15 1 * *", "59 23 LW * *" ]
5759

5860
You also can set a different Cron Trigger for each [environment](/workers/wrangler/environments/) in your [Wrangler configuration file](/workers/wrangler/configuration/). You need to put the `[triggers]` table under your chosen environment. For example:
5961

60-
61-
6262
<WranglerConfig>
6363

6464
```toml

src/content/docs/workers/examples/cron-trigger.mdx

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,9 @@ sidebar:
1313
description: Set a Cron Trigger for your Worker.
1414
---
1515

16-
import { TabItem, Tabs, WranglerConfig } from "~/components";
16+
import { Render, TabItem, Tabs, WranglerConfig } from "~/components";
1717

18-
<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
19-
20-
```js
21-
export default {
22-
async scheduled(event, env, ctx) {
23-
console.log("cron processed");
24-
},
25-
};
26-
```
27-
28-
</TabItem> <TabItem label="TypeScript" icon="seti:typescript">
29-
30-
```ts
31-
interface Env {}
32-
export default {
33-
async scheduled(
34-
controller: ScheduledController,
35-
env: Env,
36-
ctx: ExecutionContext,
37-
) {
38-
console.log("cron processed");
39-
},
40-
};
41-
```
42-
43-
</TabItem> </Tabs>
18+
<Render file="cron-trigger-example" />
4419

4520
## Set Cron Triggers in Wrangler
4621

@@ -63,8 +38,6 @@ crons = ["0 * * * *"]
6338

6439
You also can set a different Cron Trigger for each [environment](/workers/wrangler/environments/) in your [Wrangler configuration file](/workers/wrangler/configuration/). You need to put the `[triggers]` table under your chosen environment. For example:
6540

66-
67-
6841
<WranglerConfig>
6942

7043
```toml
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
{}
3+
---
4+
5+
import { TypeScriptExample } from "~/components";
6+
7+
<TypeScriptExample>
8+
```ts
9+
interface Env {}
10+
export default {
11+
async scheduled(
12+
controller: ScheduledController,
13+
env: Env,
14+
ctx: ExecutionContext,
15+
) {
16+
console.log("cron processed");
17+
},
18+
};
19+
```
20+
</TypeScriptExample>

0 commit comments

Comments
 (0)