惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
雷峰网
雷峰网
Recent Announcements
Recent Announcements
月光博客
月光博客
G
Google Developers Blog
腾讯CDC
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
T
Tenable Blog
云风的 BLOG
云风的 BLOG
W
WeLiveSecurity
博客园 - 【当耐特】
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 聂微东
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
P
Privacy International News Feed
MyScale Blog
MyScale Blog
K
Kaspersky official blog
T
The Blog of Author Tim Ferriss
Attack and Defense Labs
Attack and Defense Labs
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
aimingoo的专栏
aimingoo的专栏
I
Intezer
Vercel News
Vercel News
小众软件
小众软件
Simon Willison's Weblog
Simon Willison's Weblog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
Latest news
Latest news
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tor Project blog
S
Security Affairs
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
博客园 - Franky
C
Cyber Attacks, Cyber Crime and Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
美团技术团队
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Security @ Cisco Blogs
L
LINUX DO - 热门话题
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
D
Docker
L
Lohrmann on Cybersecurity
F
Full Disclosure

Flavio Copes

Workers Cache: a cache in front of your Cloudflare Worker Cloudflare Drop: drag a folder, get a live site Temporary Cloudflare accounts: agents can now deploy without signing up Moondream 3.1 on Workers AI: fast vision at the edge inferencecost.dev: what will AI inference cost you at 10k users? Sitebase: all the features your website needs, in one place StackPlan: figure out where to deploy your app, and what it How the Cloudflare Pages build cache works The Summer of Code How I generate an Open Graph image for every post New: 90 free tools for developers How I added search to my static site with Pagefind How to rebuild a Cloudflare site on a schedule Cloudflare Email Workers: run code when an email arrives Cloudflare Turnstile: stop bots without annoying CAPTCHAs Cloudflare Workers: secrets and environments Cloudflare Workers observability: logs and traces Cloudflare Analytics Engine: store and query metrics The AI Workshop (July 2026 cohort) Cloudflare Durable Objects: state that lives in one place Cloudflare Queues: run work in the background Cloudflare R2: object storage without egress fees Cloudflare KV: a key-value store for your Workers Cloudflare D1: a SQL database for your Workers Serving a website with Cloudflare Workers static assets Wrangler: the Cloudflare Workers command line tool Executor: one gateway to connect your AI agent to every tool Cloudflare Workers: your first serverless function Vercel eve: an open framework for building AI agents Flue: the open framework for building AI agents Val Town: write and deploy code in seconds A hands-on guide to The Agency, a collection of AI agents The AI Workshop (June 2026 cohort) The AI Workshop (May 2026 cohort) The AI Workshop (Apr 2026 cohort)
Cloudflare Cron Triggers: run a Worker on a schedule
Flavio Copes · 2026-06-28 · via Flavio Copes

By Flavio Copes

How to run a Cloudflare Worker on a schedule with Cron Triggers. Nightly jobs, periodic checks, and cleanups, with no server to keep running.

~~~

Not everything happens because someone visits a URL. Some things should just run on their own: a nightly report, a cleanup every hour, a check every five minutes.

For that, Cloudflare has Cron Triggers. You give a Worker a schedule, and Cloudflare runs it for you. No server sitting idle, no cron daemon to babysit.

Add a schedule

Schedules go in wrangler.jsonc, under triggers:

{
  "triggers": {
    "crons": ["0 2 * * *"]
  }
}

That string is a cron expression. 0 2 * * * means “every day at 2:00.” You can have more than one schedule in the array.

A few common ones:

  • */5 * * * * — every 5 minutes
  • 0 * * * * — every hour, on the hour
  • 0 2 * * * — every day at 2:00
  • 0 0 * * 1 — every Monday at midnight

If cron syntax makes your eyes glaze over, a tool like crontab.guru spells it out in plain English. I also built a free cron builder that does the same and previews the next run times.

Handle the schedule

A normal Worker has a fetch handler. A scheduled Worker has a scheduled handler instead (or as well):

export default {
  async scheduled(event, env, ctx) {
    console.log('Running the nightly job')
    // do the work here
  },
}

Cloudflare calls scheduled on your schedule. You get env with all your bindings, so you can read your database, write to storage, send email, whatever the job needs.

A real example

Here’s a nightly cleanup that deletes old rows from a D1 database:

export default {
  async scheduled(event, env, ctx) {
    const thirtyDaysAgo = Date.now() - 30 * 24 * 60 * 60 * 1000

    await env.DB.prepare(
      'delete from logs where created_at < ?'
    ).bind(thirtyDaysAgo).run()
  },
}

Set it to 0 2 * * * and your logs table cleans itself up every night while you sleep.

Be careful with time zones

Here’s the one thing that trips people up. Cron schedules run in UTC, not your local time.

So 0 9 * * * is 9:00 UTC, which might be the middle of the night where you are. If you want a job at 9:00 your time, convert to UTC first.

Long jobs and waitUntil

If your job kicks off work that shouldn’t block, wrap it in ctx.waitUntil so Cloudflare keeps the Worker alive until it finishes:

async scheduled(event, env, ctx) {
  ctx.waitUntil(generateDailyReport(env))
}

Testing it locally

You don’t want to wait until 2 AM to know if your job works. In dev, you can trigger it manually:

npx wrangler dev

Then in another terminal, hit the test endpoint Wrangler exposes:

curl "http://localhost:8787/cdn-cgi/handler/scheduled"

That runs your scheduled handler right away, so you can see it work.

What I use it for

Cron Triggers are my go-to for the quiet background chores: rolling up analytics overnight, pruning old data, checking if a site is up, sending a daily digest.

It’s the simplest way to run code on a schedule without owning a server. The full reference is in the Cron Triggers docs.

~~~

Related posts about cloudflare: