Scheduled Jobs
Queuebase supports scheduled jobs that run automatically on a cron schedule. Scheduled jobs are defined inline on your job definition and synced to the dev server on startup.
Defining a scheduled job
Section titled “Defining a scheduled job”Add a schedule property to any job with an empty input schema:
import { createJobRouter, job } from "@queuebase/nextjs";import { z } from "zod";
export const jobs = createJobRouter({ dailyReport: job({ input: z.object({}), handler: async ({ jobId }) => { // runs every day at 9am UTC return { generated: true }; }, schedule: "every day at 9am", }),});Schedule formats
Section titled “Schedule formats”The schedule property accepts three formats:
Plain English
Section titled “Plain English”Human-readable expressions that are converted to cron under the hood.
schedule: "every 5 minutes"schedule: "every hour"schedule: "every 2 hours"schedule: "every day at 9am"schedule: "every weekday at 9am"schedule: "every monday at 2pm"Raw cron
Section titled “Raw cron”Standard 5-field cron expressions.
schedule: "*/5 * * * *" // every 5 minutesschedule: "0 9 * * *" // daily at 9amschedule: "0 9 * * 1-5" // weekdays at 9amConfig object
Section titled “Config object”For full control over timezone and overlap behavior.
schedule: { cron: "0 9 * * *", timezone: "America/New_York", enabled: true, overlap: "skip",}| Field | Type | Description | Default |
|---|---|---|---|
cron | string | Cron expression or plain English string | (required) |
timezone | string | IANA timezone | UTC |
enabled | boolean | Whether the schedule is active | true |
overlap | 'skip' | 'allow' | What to do if the previous run is still executing | 'skip' |
How it works
Section titled “How it works”- Define a schedule on your job (as shown above)
- Run
npx queuebase generateto build a manifest of your jobs and schedules - Run
npx queuebase dev— the dev server reads the manifest and syncs schedules into the local database - The worker polls for scheduled jobs and calls back to your app to execute them
The manifest is written to .queuebase/queuebase.manifest.json. You should add the .queuebase/ directory to your .gitignore.
Mixing scheduled and on-demand jobs
Section titled “Mixing scheduled and on-demand jobs”A router can contain both scheduled and on-demand jobs:
export const jobs = createJobRouter({ // On-demand: enqueued by your app code sendEmail: job({ input: z.object({ to: z.string().email(), subject: z.string() }), handler: async ({ input }) => { // send email... return { sent: true }; }, }),
// Scheduled: runs automatically cleanupExpired: job({ input: z.object({}), handler: async () => { // cleanup logic... return { cleaned: true }; }, schedule: "every hour", }),});