The short answer
To run a scheduled job, write a route in your app that does the work, then ask your connected coding agent to schedule it. Antideploy sends a request to that path on your schedule. It wakes the app if it is asleep, runs the route, and lets the app go back to sleep. You do not need a background worker, and a timer inside your server will not work, because an idle app sleeps.
Say this to your coding agent
Run /api/cron/nightly every day at 3am UTC.
If your agent is not connected yet, paste this first: Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
What your agent does
-
It writes the route
A nightly task is a route. For example, a route that deletes expired sessions.
-
It creates the job
A job is a path, a method and a schedule. The method is POST unless you say GET. Five-field cron in UTC, or
@hourly,@daily,@weeklyand@monthly. -
It reads the result
Each job shows its next run and its last, the status of the last run and any error. The console has a Schedules panel for the same thing.
What the route looks like
Every run carries the header x-antideploy-cron: 1. Anyone can send a header, so a route that does real work should also check a secret that only your app knows.
app.post("/api/cron/nightly", async (req, res) => {
// anyone can send the cron header, so check a secret of your own for real work
await deleteExpiredSessions();
res.sendStatus(200);
});
The rules
- Three jobs per app, on every plan
- Runs are at least five minutes apart
- A run is given up after 60 seconds, so keep each one short
- Schedules are in UTC, so convert from your own time zone
- Ten failures in a row pause the job, and resuming it resets the count
- To change a schedule or a path, remove the job and add it again
Why not a timer in your server
A library such as node-cron, or a setInterval, needs the process to be running. Antideploy scales an idle app to zero, so the timer stops with it and never fires. Antideploy flags this before you deploy. Move the work into a route and schedule that route instead.