One-off tasks
Schedule a single call to your app from its server-side code with `createCronClient`.
Schedule a single call to your app from its server-side code with createCronClient. mybase calls the same endpoint as for scheduled jobs, signed with the cron secret. Scheduling needs a mybase API key with cron:write for the project (mybase token create shop-app --project shop --perm cron:write), not an admin one.
Schedule a task
import { createCronClient } from "@mybase-dev/sdk/cron";
const cron = createCronClient({
apiUrl: process.env.MYBASE_URL!, // mybase, reachable from your app
project: "shop",
apiKey: process.env.MYBASE_API_KEY!, // cron:write for this project
baseUrl: "https://shop.example.com", // your app, reachable from mybase
});
const task = await cron.schedule("send-reminder", {
in: "24h",
payload: { orderId: 42 },
key: "reminder-42",
});
await cron.get(task.id); // task, or null if not found
await cron.getByKey("reminder-42");
await cron.cancelByKey("reminder-42"); // only pending tasks can be cancelledHandle the call
Add a "send-reminder" job to your cronHandler's jobs map. Its run.trigger is "task", run.runId is the task ID, and run.key is the optional dedupe key.
Scheduling and delivery
inaccepts milliseconds or"30s","15m","2h","7d";ataccepts a date or date string. Omit both to run as soon as possible. You cannot pass both.keydeduplicates while a task is pending or running. After it finishes, the key is free again.pathdefaults to/api/cronand appends tobaseUrl;urloverrides both. Setretries(0–5) andtimeoutMs(1000–120000) per task if needed.- Tasks persist in Postgres. Due tasks run when mybase restarts; interrupted tasks can run again. Dedupe on
run.runIdfor non-repeatable side effects. get,getByKey,cancel, andcancelByKeyreturnnullfor unknown tasks. Cancelling an already-run task throwsMybaseApiErrorwithstatus: 409.
Finished and cancelled tasks remain for seven days. Each project can have up to 10,000 pending tasks. Keep the API key server-side.