Reports and alerts that run themselves
You shouldn't have to open five dashboards to know how your site did yesterday. This lesson sets up a nightly report e-mail for Mangrove Kitchen, sent by a scheduled job, through a route that only answers when it gets the right secret.
By the end you can
- Explain what a scheduled job is and choose between Vercel Cron and Supabase pg_cron
- Protect a report route with a secret so strangers can't trigger it
- Schedule a nightly call with pg_cron and pg_net, with the time written in UTC
- Check that a job ran, and fix one that didn't
The everyday picture
Think of a shop owner who asks the night guard to phone at 11 pm every night and read out the till total. The guard has an alarm clock, a phone number, and a code word, so nobody else can call pretending to be him and get the shop to do something. If the call doesn't come, the owner knows something is wrong.
The alarm clock is the schedule, the phone call is a web request, and the code word is your secret.
Two ways to run something on a schedule
A scheduled job is written as a cron expression. Both options below call a route on your site; the route does the work.
- Vercel Cron. Your agent adds a schedule to
vercel.json. Easy, but on the Hobby plan a job can run at most once a day and the exact minute isn't promised. If you set aCRON_SECRETvariable, Vercel sends it in the request's Authorization header for you. - Supabase pg_cron plus pg_net. pg_cron runs on a schedule inside the database, and pg_net lets that SQL call your site. Any schedule works, every 10 minutes included. This is what Kolom uses for its own nightly owner report.
One trap catches everyone: pg_cron schedules are in UTC. 23:00 in Dhaka (UTC+6) is 17:00 UTC, so you write 0 17 * * *. Work out your own offset once and write it in a comment.
Quick check
You want the report at 22:00 in Lagos (UTC+1), using pg_cron. Which schedule is right?
pg_cron reads the time as UTC, and Lagos is one hour ahead, so 22:00 there is 21:00 UTC. The last option swaps the minute and hour fields.