/lunora:lunora-setup-schedulerfrom Lunora
Configures deferred dispatch (runAfter/runAt) and recurring cron jobs in a Lunora app. Covers SchedulerDO binding, cronJobs() builder, retries, dead-lettering, and createWorkpool for bounded concurrency.
Ships in Lunora. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Lunora schedules work in two ways, both implemented in @lunora/scheduler:
ctx.scheduler.runAfter / runAt run a function (or
start a workflow) later. Jobs are stored in the SchedulerDO Durable Object
(binding SCHEDULER), which owns the alarm, the retries and the dead-letter list.lunora/crons.ts with cronJobs().
Codegen compiles them into Cloudflare Cron Triggers, and the Worker's
scheduled() handler dispatches them directly. They don't go through the
SchedulerDO.lunora-quickstart first.query /
subscription (lunora-realtime).runAfter / runAtpnpm add @lunora/scheduler
lunora codegen
Codegen needs @lunora/scheduler installed as soon as ctx.scheduler is used,
because the generated _generated/app.ts imports createScheduler. Once the
dependency is present, codegen emits _generated/scheduler.ts (re-exporting
SchedulerDO) and a .scheduler() method on the app builder.
SchedulerDO and calls .scheduler() for you.src/server.ts with defineApp): wire it yourself.
wrangler.jsonc's SCHEDULER binding is reconciled from this export:const app = defineApp<Env>()
.shard((env) => env.SHARD)
.scheduler({ namespace: (env) => env.SCHEDULER })
.build();
export const ShardDO = app.ShardDO;
export { SchedulerDO } from "../lunora/_generated/scheduler.js";
The SchedulerDO calls back into the Worker at LUNORA_ORIGIN_URL. It reads
that value from its own env and never from the request, so a caller can't point
dispatch at an arbitrary URL. Without it, every runAfter/runAt fails with
ORIGIN_NOT_CONFIGURED, and nothing provisions it for you:
LUNORA_ORIGIN_URL="http://localhost:5173" in .dev.vars (your dev
server's URL)vars.LUNORA_ORIGIN_URL in wrangler.jsonc, or
wrangler secret put LUNORA_ORIGIN_URL (per --env)lunora doctor warns when the scheduler binding exists and the variable is unset.
import { LunoraError } from "lunorash/server";
import { internal } from "#lunora/_generated/internal.js";
import { mutation } from "#lunora/_generated/server.js";
export const startTrial = mutation.mutation(async ({ ctx }) => {
// the caller's own id, never one the client passes in
const { userId } = ctx.auth;
if (!userId) {
throw new LunoraError("UNAUTHORIZED", "not signed in");
}
// run an internal action 14 days from now; the id is a plain string
const jobId = await ctx.scheduler.runAfter(14 * 24 * 60 * 60 * 1000, internal.billing.endTrial, { userId });
return { jobId };
});
ctx.scheduler surface is runAfter(delayMs, target, args?),
runAt(timestampMs, target, args?) (epoch ms), cancel(id), get(id), and list().
It is not available in a query, because queries are deterministic and re-run.target is a generated internal.* / api.* mutation or action reference, a
"file:fn" string, or a workflows.<name> / agents.<name> reference.
A workflow or agent reference starts a fresh instance when the job fires, with
args as its params. Scheduled jobs run with no end-user identity, so target
internal.* functions.cancel it later.retry policy ({ maxAttempts, backoff: "exponential" | "linear", baseMs, maxMs }) or a shardKey, build your own client with
createScheduler({ namespace }) from @lunora/scheduler. Its runAfter/runAt
take a fourth RunOptions argument and add dead() / deadRetry(id).lunora registry add crons
pnpm install
This adds @lunora/server + @lunora/scheduler to package.json and copies two
files you own: lunora/crons.ts (a cronJobs() registry) and
lunora/crons/jobs.ts (an example internalMutation, internal.crons.jobs.run).
import { cronJobs } from "@lunora/server";
import { internal } from "#lunora/_generated/internal.js";
const crons = cronJobs();
crons.interval("purge sessions", { minutes: 5 }, internal.sessions.purgeExpired, {});
crons.hourly("rollup", { minuteUTC: 17 }, internal.stats.rollup);
crons.daily("digest", { hourUTC: 9, minuteUTC: 0 }, internal.email.digest);
crons.weekly("report", { dayOfWeek: "monday", hourUTC: 8, minuteUTC: 0 }, internal.reports.weekly);
crons.monthly("invoice", { day: 1, hourUTC: 0, minuteUTC: 0 }, internal.billing.invoice);
crons.cron("custom", "0 */6 * * *", internal.foo.bar); // raw cron escape hatch
export default crons;
internal.<…path>.<fn>, one segment
per folder and file, e.g. internal.crons.jobs.run) or a workflows.<name> /
agents.<name> reference. Codegen resolves them from the AST, so a computed
reference fails codegen. args is optional and must be a literal.interval takes exactly one of
{ minutes } (must divide 60) or { hours } (must divide 24). { seconds }
is rejected because Cron Triggers have a one-minute floor. For sub-minute work,
use runAfter.hourly with an offset minute to spread jobs away from :00.lunora codegen
Codegen emits lunora/_generated/crons.ts (LUNORA_CRON_TRIGGERS plus the
LUNORA_CRONS dispatcher map, which defineApp wires into scheduled()) and
syncs triggers.crons in wrangler.jsonc. Don't hand-edit that array.
Verify: the studio's scheduled-jobs view lists each cron and has a "Run now" action, which calls the same dispatch path as a real tick.
A workpool is a named pool inside the same SchedulerDO. It needs no extra
binding. Build it in Worker code that has the raw env:
import { createWorkpool } from "@lunora/scheduler";
const pool = createWorkpool({ namespace: env.SCHEDULER, name: "imports", maxConcurrency: 3 });
await pool.enqueue(internal.imports.processRow, { rowId }, { retry: { maxAttempts: 3 } });
// pool.cancel(id), pool.status() → { inFlight, queued, maxConcurrency }
The DO dispatches at most maxConcurrency jobs at once and queues the rest
durably. One alarm drain keeps at most six dispatches in flight (the DO connection limit),
so a long-running job holds a slot for its whole duration. For individually long jobs
(LLM calls, exports), prefer createQueueWorkpool, which is backed by Cloudflare Queues.
You give up the hard cap, per-job cancel and per-job status in exchange.
ORIGIN_NOT_CONFIGURED: LUNORA_ORIGIN_URL is unset for the SchedulerDO
(see above).SchedulerDO not exported from a hand-written worker entry: wrangler
only binds classes the entry exports, so SCHEDULER is never provisioned.name or target in cronJobs(): codegen cannot discover it.lunora codegen: triggers.crons and the
dispatcher map are generated output and go stale.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
lunora, scheduler, cron-jobs, deferred-tasks, durable-objects
npx claudepluginhub anolilab/lunora --plugin lunora15 skills in this plugin
/lunoraRoutes general Lunora requests to the right Lunora skill and gives the shared mental model (codegen loop, generated `api`/`internal` references, review commands, add-on capabilities, the `@lunora/mcp` server). Use when the user asks which Lunora skill to use, gives an underspecified task in a project with a `lunora/` directory or `lunorash`/`@lunora/*` dependencies, asks to review or audit Lunora code, asks about an add-on without its own skill (queues, workflows, agents, AI, flags, payments, notifications), or wants to expose a deployment to an AI agent over MCP./lunora-cloudflare-auditAudits a Lunora app for Cloudflare cost and reliability risk before launch or after a surprise bill. Chains the read-only `lunora doctor`, `lunora advisor` and `lunora insights` signals, then traces what they cannot see — retry and fan-out loops, cron cadence, public routes that reach a metered product (Workers AI, Browser, Containers, Vectorize, R2, D1), preview environments with paid bindings, and missing usage alerts (`lunora cloudflare alerts`). Reports each finding with the billing meter it moves, the smallest fix, and how to verify. Use when the user asks to "audit before launch", "what could blow up our Cloudflare bill", "why did the bill spike", "is this safe to put on the public internet", or "review our cron / queue / AI / workflow cost". For a slow query or OCC conflict use `lunora-performance-audit`; for a failing deploy use `lunora-deploy`./lunora-create-packageBuilds a reusable Lunora capability, either as a registry item that `lunora add` / `lunora registry add` copies into an app's `lunora/`, or as a publishable `@lunora/*` workspace package in the Lunora monorepo. Use when the user wants to package schema + functions + wrangler bindings + env vars for other apps, add or edit an item under `registry/<name>/` (`registry.json`), run `vis generate lunora-package`, or wire a new `ctx.*` capability into codegen./lunora-deployDeploys a Lunora app to Cloudflare Workers + Durable Objects and gets wrangler.jsonc, remote resources and secrets to line up. Covers `lunora deploy` (and `--env`, `--dry-run`, `--migrate`), isolated per-PR previews (`lunora preview deploy | list | delete`), the `lunora doctor` / `lunora verify` / `lunora prepare` preflights, Durable Object bindings (SHARD, SHARD_REGISTRY, SCHEDULER), the `DB` D1 binding and its placeholder id, R2 buckets, production secrets (`lunora env push`, `wrangler secret put`) versus `.dev.vars`, the schema-drift gate, the architecture diff, and rollback with `lunora cloudflare deployments`. Use when the user asks to "deploy", "ship to production", "set up a staging environment", wire CI deploys, or when a deploy fails on a binding, a placeholder `database_id`, an unexported Durable Object class, a missing secret, or "schema drift gate blocked deploy"./lunora-functionsAuthoring rules for Lunora schema and server functions under `lunora/` — `defineSchema`/`defineTable`, `v.*` validators, the generated `query`/`mutation`/`action` builders (and `internal*`), indexes and `withIndex`, the `ctx.db` API, pagination, `ctx.db.related`, opt-in `ctx.*` capabilities, topics, modules, services, and `httpAction`. Use when writing or reviewing files in `lunora/` (`schema.ts`, function files, `http.ts`, `queues.ts`), when asked to "add a query/mutation/action", "add an index", "call one function from another", or "add a webhook endpoint", or when `lunora codegen` reports an error in a function./lunora-migration-helperPlans and runs Lunora schema and data migrations with the widen → migrate → narrow pattern. Covers online data migrations (`defineMigration` in `lunora/migrations.ts`, `lunora migrate create | up | down | status`), what the pre-deploy schema-drift gate treats as breaking and how a migration covers it, `.global()` table DDL on D1 (`lunora migrate generate`) and Hyperdrive, moving a dataset with `lunora migrate d1-to-hyperdrive` (and back with `hyperdrive-to-d1`), and re-keying a `.shardBy()` table. Use when the user wants to make a field required, rename or drop a field or table, change a field's type, add a unique index to a populated table, backfill data, switch a table between root / `.shardBy()` / `.global()`, or when `lunora deploy` reports "schema drift gate blocked".Other plugins' skills for the same job