Setting Cron Triggers
Set a Cron Trigger for your Worker.
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 handler
@handlerasync def on_scheduled(controller, env, ctx): print("cron processed")
import { Hono } from 'hono';
interface Env {}
// Create Hono appconst app = new Hono<{ Bindings: Env }>();
// Regular routes for normal HTTP requestsapp.get('/', (c) => c.text('Hello World!'));
// Export both the app and a scheduled functionexport 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
Section titled “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:
{ "name": "worker", "triggers": { "crons": [ "0 * * * *" ] }}
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
Section titled “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 /__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.
npx wrangler dev --test-scheduled
curl "http://localhost:8787/__scheduled?cron=0+*+*+*+*"
curl "http://localhost:8787/cdn-cgi/handler/scheduled?cron=*+*+*+*+*" # Python Workers
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark