Cron jobs
Have Lahyer call a path of your app on a schedule.
Pro plan
Cron jobs are part of the Pro plan, for server apps. See Plans and limits.
List a path of your app and a schedule under crons in lahyer.json. After each production deployment, Lahyer calls those paths on your live address on schedule: sending a report, cleaning up old rows, syncing with another service.
{
"crons": [
{ "path": "/api/cron/report", "schedule": "0 8 * * *" },
{ "path": "/api/cron/cleanup", "schedule": "*/30 * * * *" }
]
}Handle the call
Lahyer sends a GET request to the path on <project>.lahyer.app with two headers:
Authorization: Bearer <CRON_SECRET>User-Agent: lahyer-cron/1.0
Check the secret so nobody else can trigger the job. Lahyer sets CRON_SECRET on every production deployment that lists cron jobs; to choose the value yourself, add a CRON_SECRET environment variable for production and redeploy.
export async function GET(request: Request) {
if (request.headers.get("authorization") !== `Bearer ${process.env.CRON_SECRET}`) {
return new Response("Unauthorized", { status: 401 });
}
await sendDailyReport();
return Response.json({ ok: true });
}A run succeeds when the app answers with a 2xx status within 60 seconds. Anything else fails the run, and the Cron jobs tab says why:
- A redirect fails: a cron path must answer itself.
401or403means the app refused the secret.404means the live deployment has nothing at that path.- No answer within 60 seconds.
Schedules
Schedules use the five standard cron fields, always in UTC:
┌───────────── minute (0-59)
│ ┌─────────── hour (0-23)
│ │ ┌───────── day of month (1-31)
│ │ │ ┌─────── month (1-12)
│ │ │ │ ┌───── day of week (0-7, Sunday is 0 or 7)
│ │ │ │ │
0 8 * * *Each field takes a number, *, a range (1-5), a list (1,15) or a step (*/30, 0-12/2). Names such as MON or JAN and the extensions ?, L, W and # are not accepted.
| Schedule | Runs |
|---|---|
0 8 * * * | Every day at 08:00 UTC |
*/15 * * * * | Every 15 minutes |
0 */6 * * * | Every six hours |
30 7 * * 1-5 | 07:30 UTC, Monday to Friday |
0 0 1 * * | Midnight UTC on the first of every month |
Jobs can run as often as every 15 minutes: a schedule with a shorter gap fails the build. Server apps sleep after five quiet minutes, so anything more frequent would keep yours awake around the clock.
The Cron jobs tab
The project's Cron jobs tab lists every job from the live deployment's lahyer.json with its next and last run, and the recent runs with their status and duration. From there you can:
- Run now, to try a job without waiting for its schedule.
- Pause a job, and resume it later. A paused job stays paused through new deployments as long as its path and schedule stay the same.
Runs are kept for 30 days.
Rules
- Up to 20 cron jobs per project. The same path and schedule cannot be listed twice.
- A path starts with
/, is on your app's own address and is not under/.lahyer/. It may carry a query string, such as/api/cron/report?kind=daily. - Cron jobs need a server app. A static site that lists cron jobs fails its build.
- Only production is called. Previews never run cron jobs.