[TBF] Kevin Ossen₿rück
CDCloudflare Developers
•Created by amorfati on 2/18/2025 in #workers-help
Cron Trigger every 10 seconds
🤗 I prefer Wrangler CLI together with IntelliJ IDEA as development environment for Workers.
13 replies
CDCloudflare Developers
•Created by amorfati on 2/18/2025 in #workers-help
Cron Trigger every 10 seconds
To create a "Hello World" cron worker using Cloudflare Workers, follow these steps:
1. Set Up Your Worker Project
First, install the
create-cloudflare
package to scaffold a new Worker project:
During setup, select the "Hello World example" and choose "JavaScript" as your language. citeturn0search3
2. Add a Scheduled Event Listener
In your project directory, navigate to the src
folder and open index.js
. Modify it to include a scheduled
event listener:
This code logs "Hello, World!" each time the scheduled event triggers. citeturn0search2
3. Configure the Cron Trigger
Define when your Worker should run by setting up a cron trigger. In your wrangler.toml
file, add the following configuration:
This schedule runs the Worker at the top of every hour. citeturn0search0
4. Deploy Your Worker
To deploy your Worker with the cron trigger, use Wrangler:
Ensure you're authenticated with your Cloudflare account before deploying. citeturn0search3
5. Testing the Cron Trigger
While cron triggers run based on the defined schedule, you can test them locally:
This command starts a local server and exposes a /__scheduled
route. You can simulate the cron trigger by making an HTTP request:
This simulates a cron pattern matching every minute. citeturn0search2
By following these steps, you've set up a Cloudflare Worker that logs "Hello, World!" based on a scheduled cron trigger.13 replies
CDCloudflare Developers
•Created by amorfati on 2/18/2025 in #workers-help
Cron Trigger every 10 seconds
13 replies