GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Schedule

Run server code at set times. One file deploys as cron on your host.

server/schedules/daily-report.tsSame on every host
import { defineSchedule } from 'vite-hub/schedule'

// Runs every day at 08:00 UTC.
export default defineSchedule({
  cron: '0 8 * * *',
  handler({ scheduledAt }) {
    console.log('Report for', scheduledAt.toISOString())
  },
})
server/schedules/daily-report.ts
Deploy on

Node / Docker: process

One file per schedule

Create a file in server/schedules. The file name is the schedule name. Cron uses UTC unless you set timeZone.

Test without waiting

Run a Static Schedule by hand with vitehub schedule run or from the Console, unless it sets manual: false.

Uses the cron your host has

On Cloudflare and Vercel, the build writes the host's cron settings.

Start a schedule from code

Leave out cron, then call startSchedule() with a time or a cron that your users pick. It survives restarts.

Run on your own server

On Node, a long-running server process checks for due schedules each minute. Not for serverless hosts.