mybasev1.0.21

Define jobs in code

Use `defineConfig` to declare schedules in `mybase.config.ts` at your app root.

Use defineConfig to declare schedules in mybase.config.ts at your app root. The CLI imports this file when syncing, so keep application code and secrets out of it; handlers belong in your HTTP endpoint.

Declare jobs

// mybase.config.ts
import { defineConfig } from "@mybase-dev/sdk/config";

export default defineConfig({
  project: "shop",
  cron: {
    baseUrl: "https://shop.example.com",
    jobs: {
      cleanup: { schedule: "0 3 * * *" },
      digest: {
        schedule: "0 8 * * 1",
        timezone: "America/Chicago",
        path: "/api/cron",
        payload: { kind: "weekly" },
      },
    },
  },
});

baseUrl must be reachable from the mybase server. The default path is /api/cron. Schedules have five fields (minute precision); the default time zone is UTC.

Sync with mybase

mybase cron sync --dry-run
mybase cron sync

Sync creates, updates, and deletes code-defined jobs to match the file. It never changes jobs created in the dashboard.

Job options

Job optionDefaultMeaning
schedulerequiredFive-field cron expression
path/api/cronAppended to baseUrl
timezoneUTCIANA time zone
payloadnoneJSON sent to the handler, up to 16 KB
retries2Extra tries, 0–5
timeoutMs30000Per-call timeout, 1000–120000 ms

Typed handlers

For typed job names in a handler, import the config type and call cronHandler<typeof config>({ ... }). See handling cron calls.

On this page