Setting Cron Triggers

Set a Cron Trigger for your Worker.

Last updated Sep 4, 2026

export default {
    async scheduled(controller, env, ctx) {
        console.log("cron processed");
    },
};
interface Env {}
export default {
    async scheduled(
        controller: ScheduledController,
        env: Env,
        ctx: ExecutionContext,
    ) {
        console.log("cron processed");
    },
};
from workers import WorkerEntrypoint, Response

class Default(WorkerEntrypoint):
    async def scheduled(self, controller, env, ctx):
            print("cron processed")
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 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:

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

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

You also can set a different Cron Trigger for each environment in your Wrangler configuration file. You need to put the [triggers] table under your chosen environment. For example:

{
    "env": {
        "dev": {
            "triggers": {
                "crons": [
                    "0 * * * *"
                ]
            }
        }
    }
}
[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. This will expose a /cdn-cgi/local/scheduled route which can be used to test using a HTTP request. To simulate different cron patterns, a cron query parameter can be passed in.

npx wrangler dev --test-scheduled

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

Was this helpful?

YesNo

On this page

Setting Cron Triggers - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/examples/cron-trigger/#page","headline":"Setting Cron Triggers","description":"Set a Cron Trigger for your Worker.","url":"https://developers.cloudflare.com/workers/examples/cron-trigger/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/examples/cron-trigger/og.png?v=f65c3e19a9b740ba","dateModified":"2026-09-04","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["Middleware","JavaScript","TypeScript"]}


description: Protect sensitive data to prevent data loss, and send alerts to a webhooks server in the event of a data breach. title: Data loss prevention image: https://developers.cloudflare.com/workers/examples/data-loss-prevention/og.png?v=7c8e7c60f802c9b3


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.