Urgent.News

the world's headlines, one feed

Editions

Tech

Testing Cloudflare Cron Triggers Locally for Push Notification Workflows

This article is an English translation of the original Japanese article. I use Cloudflare Workers Cron Triggers to send push notifications on the morning of practice days. The challenge was figuring out how to verify the entire workflow locally without waiting for the scheduled cron time. In my implementation, I separate the Worker's scheduled event from the HTTP route that handles the…

This translation relates to testing push notification workflows using Cloudflare Workers Cron Triggers. The goal is to verify the entire process locally without having to wait for the scheduled time. The solution separates the scheduled event from the HTTP route responsible for handling notifications. The main Worker receives the cron event, then forwards it to an internal HTTP route for actual notification processing.

To test locally, use Wrangler with the "--test-scheduled" option. Append "/__scheduled" to the local URL to initiate the test. The cron expression should be provided in the query parameter. Remember that Cloudflare uses UTC time, not JST, so adjust expressions accordingly.

For a more targeted verification, you can call the internal route directly with a POST request. This allows for checking recipient filtering without the need for all the data to be present in the local environment. Authentication for local development is handled separately, using a development value stored in a configuration file instead of the production secret.

When testing, ensure the cron reaches the route, the date is correct after timezone conversion, target schedules and participants are retrieved properly, users without push tokens are filtered out, and external API responses are recorded accurately. The main challenge in cron testing isn't triggering it, but rather coordinating test data with the current time. By separating the core logic into an HTTP route, you can verify event wiring and notification logic independently.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — it may contain errors, so check the original before relying on it.

Read the original at dev.to →

More in Tech

Mercedes-Benz Korea Faces Collective Dispute Over EV Battery Information

The controversy surrounding Mercedes-Benz Korea’s disclosure of electric vehicle battery cell manufacturers is escalating into a consumer compensation dispute.

  • Mercedes-Benz Korea faces consumer dispute over EV battery information.
  • Five Mercedes-Benz electric models involved in the dispute.
  • FTC fined Mercedes-Benz for misleading battery manufacturer claims.

Why Is My SQL Query Slow Only in Production? (The Parameter Sniffing Trap)

It’s every developer's favorite Friday afternoon nightmare: A user complains that a feature in the app is hanging. You take the exact SQL query executed by the application, paste it into SQL Server…

  • Parameter sniffing causes slow SQL queries in production only
  • SQL Server compiles execution plan based on initial parameter values
  • Detect problematic plans using dynamic management view (DMV)