# Schedule

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

Hosts: Cloudflare, Vercel, Deno, Node, Docker.

:hero-figure{name="schedule"}

```ts [server/schedules/daily-report.ts]
import { defineSchedule } from 'vite-hub/schedule'

// Runs every day at 08:00 UTC.
export default defineSchedule({
  cron: '0 8 * * *',
  // You can also start it by hand to test it
  manual: true,
  handler({ scheduledAt }) {
    console.log('Report for', scheduledAt.toISOString())
  },
})
```

:::framework{name="Nuxt"}
```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: {
    host: 'node',
    // Keeps Schedule Run history across restarts
    kv: true,
    // Checks for due schedules every minute
    schedule: { runtime: { driver: 'process' } },
  },
})
```
:::
:::framework{name="Nitro"}
```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: 'node',
      // Keeps Schedule Run history across restarts
      kv: true,
      // Checks for due schedules every minute
      schedule: { runtime: { driver: 'process' } },
    }),
    nitro(),
  ],
})
```
:::
:::framework{name="Vite"}
```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: 'node',
      // Keeps Schedule Run history across restarts
      kv: true,
      // Checks for due schedules every minute
      schedule: { runtime: { driver: 'process' } },
    }),
  ],
})
```
:::

### [One file per schedule](https://vitehub.dev/docs/schedule/configure#define-a-static-schedule)

Add a file to `server/schedules`. The file name is the schedule name. Cron uses UTC unless you set `timeZone`.

### [Test without waiting](https://vitehub.dev/docs/schedule/configure#schedule-definition-options)

`manual: true` lets you start a schedule at any time.

### [Uses the cron your host has](https://vitehub.dev/docs/schedule/hosts#provider-output)

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

### [Start a schedule from code](https://vitehub.dev/docs/schedule/server-api#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](https://vitehub.dev/docs/schedule/configure#configure-the-vite-integration)

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

Use Schedule for recurring wakeups or static cron declarations. When users pick the time, such as reminders, define the Schedule without `cron` and call `startSchedule(name, { at | cron, timeZone, payload })` from `vite-hub/schedule`. A scheduled run should hand off to idempotent application or Agent work.

Keep the schedule definition separate from the work it starts. Use a stable key and record the last completed run when the action must not repeat.

Prove one manual run, one scheduled wake, retry or overlap behavior, and the terminal state. Inspect generated cron or provider output.

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/schedule.md) (this page)
- [Get started](https://vitehub.dev/raw/docs/schedule/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/schedule/configure.md)
- [Server API](https://vitehub.dev/raw/docs/schedule/server-api.md)
- [Hosts](https://vitehub.dev/raw/docs/schedule/hosts.md)
- [OS timers](https://vitehub.dev/raw/docs/schedule/os-timers.md)

Next: [SCHEDULE_B0001](https://vitehub.dev/raw/docs/schedule/diagnostics/schedule_b0001.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
