---
title: Setting Cron Triggers
description: Set a Cron Trigger for your Worker.
image: https://edgetunnel-b2h.pages.dev/dev-products-preview.png
---

> Documentation Index  
> Fetch the complete documentation index at: https://edgetunnel-b2h.pages.dev/workers/llms.txt  
> Use this file to discover all available pages before exploring further. 

[Skip to content](#%5Ftop) 

# Setting Cron Triggers

Set a Cron Trigger for your Worker.

* [  JavaScript ](#tab-panel-12508)
* [  TypeScript ](#tab-panel-12509)
* [  Python ](#tab-panel-12510)
* [  Hono ](#tab-panel-12511)

**JavaScript**

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

**TypeScript**

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

**Python**

```python
from workers import WorkerEntrypoint, Response


class Default(WorkerEntrypoint):
    async def scheduled(self, controller, env, ctx):
        print("cron processed")
```

**TypeScript**

```ts
import { Hono } from "hono";


interface Env {}


// Create Hono app
const app = new Hono<{ Bindings: Env }>();


// Regular routes for normal HTTP requests
app.get("/", (c) => c.text("Hello World!"));


// Export both the app and a scheduled function
export default {
  // The Hono app handles regular HTTP requests
  fetch: app.fetch,


  // The scheduled function handles Cron triggers
  async scheduled(
    controller: ScheduledController,
    env: Env,
    ctx: ExecutionContext,
  ) {
    console.log("cron processed");


    // You could also perform actions like:
    // - Fetching data from external APIs
    // - Updating KV or Durable Object storage
    // - Running maintenance tasks
    // - Sending notifications
  },
};
```

## Set Cron Triggers in Wrangler

Refer to [Cron Triggers](https://edgetunnel-b2h.pages.dev/workers/configuration/cron-triggers/) for more information on how to add a Cron Trigger.

If you are deploying with Wrangler, set the cron syntax (once per hour as shown below) by adding this to your Wrangler file:

* [  wrangler.jsonc ](#tab-panel-12512)
* [  wrangler.toml ](#tab-panel-12513)

**JSONC**

```jsonc
{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "name": "worker",
  // ...
  "triggers": {
    "crons": [
      "0 * * * *"
    ]
  }
}
```

**TOML**

```toml
"$schema" = "./node_modules/wrangler/config-schema.json"
name = "worker"


[triggers]
crons = [ "0 * * * *" ]
```

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

* [  wrangler.jsonc ](#tab-panel-12514)
* [  wrangler.toml ](#tab-panel-12515)

**JSONC**

```jsonc
{
  "env": {
    "dev": {
      "triggers": {
        "crons": [
          "0 * * * *"
        ]
      }
    }
  }
}
```

**TOML**

```toml
[env.dev.triggers]
crons = [ "0 * * * *" ]
```

## Test Cron Triggers using Wrangler

The recommended way of testing Cron Triggers is using Wrangler.

Cron Triggers can be tested using Wrangler by passing in the `--test-scheduled` flag to [wrangler dev](https://edgetunnel-b2h.pages.dev/workers/wrangler/commands/general/#dev). This will expose a `/__scheduled` (or `/cdn-cgi/handler/scheduled` for Python Workers) route which can be used to test using a HTTP request. To simulate different cron patterns, a `cron` query parameter can be passed in.

```sh
npx wrangler dev --test-scheduled


curl "http://localhost:8787/__scheduled?cron=0+*+*+*+*"


curl "http://localhost:8787/cdn-cgi/handler/scheduled?cron=*+*+*+*+*" # Python Workers
```

```json
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://edgetunnel-b2h.pages.dev/workers/examples/cron-trigger/#page","headline":"Setting Cron Triggers · Cloudflare Workers docs","description":"Set a Cron Trigger for your Worker.","url":"https://edgetunnel-b2h.pages.dev/workers/examples/cron-trigger/","inLanguage":"en","image":"https://edgetunnel-b2h.pages.dev/dev-products-preview.png","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","url":"https://www.cloudflare.com/"},"isPartOf":{"@type":"WebSite","@id":"https://edgetunnel-b2h.pages.dev/#website","name":"Cloudflare Docs","url":"https://edgetunnel-b2h.pages.dev/"},"keywords":["Middleware","JavaScript","TypeScript"]}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/workers/","name":"Workers"}},{"@type":"ListItem","position":3,"item":{"@id":"/workers/examples/","name":"Examples"}},{"@type":"ListItem","position":4,"item":{"@id":"/workers/examples/cron-trigger/","name":"Setting Cron Triggers"}}]}
```
