Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/content/docs/workers/configuration/cron-triggers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ head: []
description: Enable your Worker to be executed on a schedule.
---

import { WranglerConfig } from "~/components";
import { Render, WranglerConfig } from "~/components";

## Background

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

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

Refer to the following examples to write your code:
<Render file="cron-trigger-example" />

Refer to the following additional examples to write your code:

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

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:



<WranglerConfig>

```toml
Expand Down
31 changes: 2 additions & 29 deletions src/content/docs/workers/examples/cron-trigger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,9 @@ sidebar:
description: Set a Cron Trigger for your Worker.
---

import { TabItem, Tabs, WranglerConfig } from "~/components";
import { Render, TabItem, Tabs, WranglerConfig } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">

```js
export default {
async scheduled(event, env, ctx) {
console.log("cron processed");
},
};
```

</TabItem> <TabItem label="TypeScript" icon="seti:typescript">

```ts
interface Env {}
export default {
async scheduled(
controller: ScheduledController,
env: Env,
ctx: ExecutionContext,
) {
console.log("cron processed");
},
};
```

</TabItem> </Tabs>
<Render file="cron-trigger-example" />

## Set Cron Triggers in Wrangler

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

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:



<WranglerConfig>

```toml
Expand Down
20 changes: 20 additions & 0 deletions src/content/partials/workers/cron-trigger-example.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
{}
---

import { TypeScriptExample } from "~/components";

<TypeScriptExample>
```ts
interface Env {}
export default {
async scheduled(
controller: ScheduledController,
env: Env,
ctx: ExecutionContext,
) {
console.log("cron processed");
},
};
```
</TypeScriptExample>
Loading