DEV Community

niuniu
niuniu

Posted on

Quick Tip: Free Cron Jobs on Cloudflare Workers (No Server, No Bill)

Quick Tip

Need a scheduled job but don't want to pay for a VPS or keep a laptop awake? Cloudflare Workers' free tier gives you cron triggers — 100,000 requests/day, $0.

wrangler.toml:

name = "nightly-cleanup"
main = "src/index.js"
compatibility_date = "2026-01-01"

[triggers]
crons = ["0 3 * * *"]   # every day at 03:00 UTC
Enter fullscreen mode Exit fullscreen mode

src/index.js:

export default {
  async scheduled(event, env, ctx) {
    // runs on the cron schedule — no HTTP request needed
    const res = await fetch("https://api.example.com/cleanup", {
      method: "POST",
      headers: { "Authorization": `Bearer ${env.API_TOKEN}` }
    });
    console.log("cleanup status:", res.status);
  }
};
Enter fullscreen mode Exit fullscreen mode

Deploy:

npx wrangler deploy
Enter fullscreen mode Exit fullscreen mode

The Numbers That Matter

Cloudflare Workers free GitHub Actions cron $5 VPS
Cost $0 $0 (public repos) $60/yr
Min interval 1 minute ~5+ min (often delayed) 1 minute
Cold start 0ms (no cold starts) 30-60s runner spin-up none
Max runtime 30s CPU (free) 6 hours unlimited

The killer detail: Workers have zero cold start. Unlike Lambda, your cron fires instantly at the scheduled second.

Gotchas (Learned the Hard Way)

  1. Cron runs in UTC only0 3 * * * is 3am UTC, not your timezone. I had a "midnight cleanup" running at 8pm local for a week.
  2. 30-second CPU limit on free tier — fine for API calls and cleanup, not for batch processing. Long jobs: split with Queues.
  3. Secrets need wrangler secret put — don't commit tokens to wrangler.toml.
npx wrangler secret put API_TOKEN
Enter fullscreen mode Exit fullscreen mode

I've replaced a $5/month VPS with 4 of these cron Workers. Total monthly bill: $0, and the jobs run faster than they did on the VPS.

More free-stack tricks I actually use: https://ly.cyberserval.tech/iIETXiF

What's the dumbest thing you're still paying a server to do on a schedule? Drop it below — I'd bet there's a free tier that covers it.

python #coding #tips

Top comments (0)