Functions

Scheduled functions

Run a function on a cron schedule without operating a scheduler. Each schedule trigger owns exactly one cron entry; runs pass through the same quotas, logging and retries as every other trigger.

Configure a schedule

In the function editor open Triggers → Add trigger → Scheduled. Provide a standard 5-field cron expression and a timezone (UTC by default, any IANA name accepted).

Trigger configuration · 03:00 UTC daily
{
  "kind": "schedule",
  "config": {
    "cron": "0 3 * * *",
    "timezone": "UTC"
  }
}
  • The trigger row shows the last run (with its outcome) and the next scheduled run.
  • Editing a schedule replaces it in place — deployments never create duplicate active schedules.
  • Disabling the trigger stops future runs immediately; deleting it removes the schedule.
  • The number of enabled schedules per project is plan-limited.

The tick payload and missed runs

The handler receives request.event of type schedule.tick with the cron expression, the scheduled time and the timezone. If the platform was down at the scheduled moment, missed runs collapse into a single catch-up run rather than a burst.

Nightly cleanup
export default async function handler(request: any, ctx: any) {
  // request.event.type is 'schedule.tick'; the cron cursor already advanced.
  // Equality filters only in ctx.db — for time ranges, find ids with
  // read-only SQL, then delete by primary key.
  const stale = await ctx.db.query(
    "SELECT id FROM public.sessions WHERE expires_at < now() - interval '30 days' LIMIT 500",
  );
  let deleted = 0;
  for (const row of stale.rows ?? []) {
    await ctx.db.from('sessions').delete({ id: row.id });
    deleted += 1;
  }
  console.log('Cleanup deleted', deleted, 'rows');
  return { deleted };
}

Additional resources