@lunora/cli 1.0.0-alpha.37 → 1.0.0-alpha.370
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +33 -0
- package/README.md +1 -1
- package/dist/bin.mjs +2 -10
- package/dist/index.d.mts +1007 -372
- package/dist/index.d.ts +1007 -372
- package/dist/index.mjs +1 -19
- package/dist/packem_chunks/dispatch.mjs +1 -0
- package/dist/packem_chunks/handler.mjs +1 -160
- package/dist/packem_chunks/handler10.mjs +2 -16
- package/dist/packem_chunks/handler11.mjs +1 -22
- package/dist/packem_chunks/handler12.mjs +1 -192
- package/dist/packem_chunks/handler13.mjs +1 -131
- package/dist/packem_chunks/handler14.mjs +1 -65
- package/dist/packem_chunks/handler15.mjs +3 -58
- package/dist/packem_chunks/handler16.mjs +1 -80
- package/dist/packem_chunks/handler17.mjs +1 -43
- package/dist/packem_chunks/handler18.mjs +1 -105
- package/dist/packem_chunks/handler19.mjs +7 -170
- package/dist/packem_chunks/handler2.mjs +1 -114
- package/dist/packem_chunks/handler20.mjs +1 -94
- package/dist/packem_chunks/handler21.mjs +1 -94
- package/dist/packem_chunks/handler22.mjs +3 -0
- package/dist/packem_chunks/handler23.mjs +3 -0
- package/dist/packem_chunks/handler24.mjs +1 -0
- package/dist/packem_chunks/handler25.mjs +2 -0
- package/dist/packem_chunks/handler26.mjs +1 -0
- package/dist/packem_chunks/handler27.mjs +99 -0
- package/dist/packem_chunks/handler28.mjs +10 -0
- package/dist/packem_chunks/handler3.mjs +1 -204
- package/dist/packem_chunks/handler4.mjs +1 -33
- package/dist/packem_chunks/handler5.mjs +1 -49
- package/dist/packem_chunks/handler6.mjs +3 -91
- package/dist/packem_chunks/handler7.mjs +1 -42
- package/dist/packem_chunks/handler8.mjs +1 -174
- package/dist/packem_chunks/handler9.mjs +1 -315
- package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
- package/dist/packem_chunks/runDeployCommand.mjs +11 -594
- package/dist/packem_chunks/runDevCommand.mjs +2 -0
- package/dist/packem_chunks/runInitCommand.mjs +164 -1432
- package/dist/packem_chunks/runResetCommand.mjs +1 -41
- package/dist/packem_chunks/runRpcCommand.mjs +1 -68
- package/dist/packem_shared/COMMANDS-CWnIJmxM.mjs +1 -0
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-CyIsI3S1.mjs +1 -0
- package/dist/packem_shared/EXIT_CODE-D_XCixv8.mjs +1 -0
- package/dist/packem_shared/admin-token-VdUnvnKW.mjs +1 -0
- package/dist/packem_shared/admin-url-DJB8P6Jh.mjs +1 -0
- package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
- package/dist/packem_shared/buildRegistryIndex-Dc8D8AR6.mjs +1 -0
- package/dist/packem_shared/catalog-CahzmDLV.mjs +1 -0
- package/dist/packem_shared/cli-6BRlq6nw.mjs +2 -0
- package/dist/packem_shared/cli-manifest-CRet0egA.mjs +1 -0
- package/dist/packem_shared/cloudflare-credentials-lC5JtPLe.mjs +1 -0
- package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
- package/dist/packem_shared/command-CAXl2A1S.mjs +1 -0
- package/dist/packem_shared/commands-DgUDxkA8.mjs +13 -0
- package/dist/packem_shared/createLogger-Cl18I8AX.mjs +2 -0
- package/dist/packem_shared/createRecordingSpawner-Ch7zuQQE.mjs +1 -0
- package/dist/packem_shared/deploy-target-DCWwiuAe.mjs +1 -0
- package/dist/packem_shared/diffSnapshots-WWwx-KvZ.mjs +5 -0
- package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
- package/dist/packem_shared/health-probe-Bw9JFfIy.mjs +1 -0
- package/dist/packem_shared/import-BRM1hs7j.mjs +12 -0
- package/dist/packem_shared/index-oHZBGBwB.mjs +1 -0
- package/dist/packem_shared/insertSchemaExtension-DuiV6cba.mjs +8 -0
- package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
- package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
- package/dist/packem_shared/output-format-B4eQHi5y.mjs +2 -0
- package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
- package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
- package/dist/packem_shared/plan-DJeIwzFu.mjs +5 -0
- package/dist/packem_shared/planDevCommand-DkaC-fNF.mjs +1 -0
- package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
- package/dist/packem_shared/prompt-cancelled-BvsNxg_Q.mjs +1 -0
- package/dist/packem_shared/render-lunora-error-C3OJY5wk.mjs +2 -0
- package/dist/packem_shared/resolve-BrsV4Qyc.mjs +5 -0
- package/dist/packem_shared/resolve-target-C_ZloTvd.mjs +1 -0
- package/dist/packem_shared/runAddCommand-DTvfp4h2.mjs +1 -0
- package/dist/packem_shared/runExportCommand-slAq5BCF.mjs +5 -0
- package/dist/packem_shared/runMigrateGenerateCommand-Ii_WMZEA.mjs +11 -0
- package/dist/packem_shared/schemaIrToSnapshot-BjK-0IRo.mjs +1 -0
- package/dist/packem_shared/secret-key-BCrqNJ68.mjs +1 -0
- package/dist/packem_shared/shared-D-zCOmgY.mjs +1 -0
- package/dist/packem_shared/storage-DWhTX8eS.mjs +1 -0
- package/dist/packem_shared/tui-prompts-B3YwUhGw.mjs +4 -0
- package/dist/packem_shared/variables-acxcvVQa.mjs +1 -0
- package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
- package/dist/packem_shared/wrangler-secrets-3chIVv3H.mjs +1 -0
- package/package.json +39 -19
- package/skills/README.md +35 -17
- package/skills/lunora/SKILL.md +154 -64
- package/skills/lunora-create-package/SKILL.md +97 -84
- package/skills/lunora-deploy/SKILL.md +175 -105
- package/skills/lunora-functions/SKILL.md +362 -56
- package/skills/lunora-migration-helper/SKILL.md +162 -137
- package/skills/lunora-performance-audit/SKILL.md +137 -95
- package/skills/lunora-quickstart/SKILL.md +137 -136
- package/skills/lunora-realtime/SKILL.md +140 -99
- package/skills/lunora-setup-auth/SKILL.md +162 -102
- package/skills/lunora-setup-hyperdrive/SKILL.md +114 -97
- package/skills/lunora-setup-hyperdrive-global/SKILL.md +93 -90
- package/skills/lunora-setup-mail/SKILL.md +85 -113
- package/skills/lunora-setup-scheduler/SKILL.md +132 -96
- package/skills/lunora-setup-storage/SKILL.md +189 -95
- package/dist/packem_chunks/planDevCommand.mjs +0 -541
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +0 -397
- package/dist/packem_shared/COMMANDS-B0ftFD_3.mjs +0 -948
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
- package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
- package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
- package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
- package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +0 -31
- package/dist/packem_shared/command-D3lB_4Az.mjs +0 -19
- package/dist/packem_shared/commands-B-gR09Z_.mjs +0 -845
- package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
- package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
- package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
- package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
- package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
- package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
- package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
- package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
- package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
- package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
- package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +0 -9
- package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
- package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +0 -4
- package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
- package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
- package/dist/packem_shared/storage-BIsph-Vk.mjs +0 -84
- package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +0 -658
- package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
- package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +0 -47
|
@@ -1,157 +1,193 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: lunora-setup-scheduler
|
|
3
|
-
description: Schedules deferred and recurring work in a Lunora app.
|
|
3
|
+
description: Schedules deferred and recurring work in a Lunora app. Covers `ctx.scheduler.runAfter` / `runAt` (delayed dispatch of a function or workflow), cron jobs in `lunora/crons.ts` via `lunora registry add crons` and the `cronJobs()` builder, the `SchedulerDO` / `SCHEDULER` binding and `LUNORA_ORIGIN_URL`, retries and dead-lettering, and `createWorkpool` for bounded concurrency. Use when the user wants to "run this later", "send a reminder in 3 days", "run every night / every 5 minutes", add a cron, cancel a scheduled job, or sees `ORIGIN_NOT_CONFIGURED` or a missing `SchedulerDO` export.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Lunora Setup Scheduler
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
from `@lunora/server`):
|
|
8
|
+
Lunora schedules work in two ways, both implemented in `@lunora/scheduler`:
|
|
10
9
|
|
|
11
|
-
- **Deferred dispatch
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
- **Deferred dispatch**: `ctx.scheduler.runAfter` / `runAt` run a function (or
|
|
11
|
+
start a workflow) later. Jobs are stored in the `SchedulerDO` Durable Object
|
|
12
|
+
(binding `SCHEDULER`), which owns the alarm, the retries and the dead-letter list.
|
|
13
|
+
- **Recurring jobs (crons)**: declared in `lunora/crons.ts` with `cronJobs()`.
|
|
14
|
+
Codegen compiles them into Cloudflare Cron Triggers, and the Worker's
|
|
15
|
+
`scheduled()` handler dispatches them directly. They don't go through the
|
|
16
|
+
`SchedulerDO`.
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
which owns the alarm and durable storage.
|
|
18
|
+
## When Not to Use
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
- The project has no Lunora backend yet: use `lunora-quickstart` first.
|
|
21
|
+
- You only need to react to data changes: use a reactive `query` /
|
|
22
|
+
subscription (`lunora-realtime`).
|
|
23
|
+
- Multi-step orchestration with sleeps and waits belongs in a durable workflow.
|
|
24
|
+
A scheduler or cron can start one, but don't build step logic on top of jobs.
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
(`runAfter` / `runAt`).
|
|
23
|
-
- Declaring recurring jobs (sweep, digest, report) on a cron schedule.
|
|
24
|
-
- Bounding concurrency for many enqueued jobs (a workpool).
|
|
26
|
+
## Deferred dispatch: `runAfter` / `runAt`
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
### Wire it once
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
```bash
|
|
31
|
+
pnpm add @lunora/scheduler
|
|
32
|
+
lunora codegen
|
|
33
|
+
```
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
Codegen needs `@lunora/scheduler` installed as soon as `ctx.scheduler` is used,
|
|
36
|
+
because the generated `_generated/app.ts` imports `createScheduler`. Once the
|
|
37
|
+
dependency is present, codegen emits `_generated/scheduler.ts` (re-exporting
|
|
38
|
+
`SchedulerDO`) and a `.scheduler()` method on the app builder.
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
- **Vite-first apps** (generated worker entry): the plugin forwards
|
|
41
|
+
`SchedulerDO` and calls `.scheduler()` for you.
|
|
42
|
+
- **Hand-written worker entry** (`src/server.ts` with `defineApp`): wire it yourself.
|
|
43
|
+
`wrangler.jsonc`'s `SCHEDULER` binding is reconciled from this export:
|
|
36
44
|
|
|
37
45
|
```ts
|
|
38
|
-
|
|
46
|
+
const app = defineApp<Env>()
|
|
47
|
+
.shard((env) => env.SHARD)
|
|
48
|
+
.scheduler({ namespace: (env) => env.SCHEDULER })
|
|
49
|
+
.build();
|
|
50
|
+
|
|
51
|
+
export const ShardDO = app.ShardDO;
|
|
52
|
+
export { SchedulerDO } from "../lunora/_generated/scheduler.js";
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The `SchedulerDO` calls back into the Worker at `LUNORA_ORIGIN_URL`. It reads
|
|
56
|
+
that value from its own env and never from the request, so a caller can't point
|
|
57
|
+
dispatch at an arbitrary URL. Without it, every `runAfter`/`runAt` fails with
|
|
58
|
+
`ORIGIN_NOT_CONFIGURED`, and nothing provisions it for you:
|
|
39
59
|
|
|
40
|
-
|
|
60
|
+
- dev: `LUNORA_ORIGIN_URL="http://localhost:5173"` in `.dev.vars` (your dev
|
|
61
|
+
server's URL)
|
|
62
|
+
- prod: `vars.LUNORA_ORIGIN_URL` in `wrangler.jsonc`, or
|
|
63
|
+
`wrangler secret put LUNORA_ORIGIN_URL` (per `--env`)
|
|
41
64
|
|
|
42
|
-
|
|
43
|
-
// run an internal action 14 days from now
|
|
44
|
-
const { id } = await ctx.scheduler.runAfter(14 * 24 * 60 * 60 * 1000, internal.billing.endTrial, { userId });
|
|
65
|
+
`lunora doctor` warns when the scheduler binding exists and the variable is unset.
|
|
45
66
|
|
|
46
|
-
|
|
67
|
+
### Schedule from a mutation or action
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { LunoraError } from "lunorash/server";
|
|
71
|
+
|
|
72
|
+
import { internal } from "#lunora/_generated/internal.js";
|
|
73
|
+
import { mutation } from "#lunora/_generated/server.js";
|
|
74
|
+
|
|
75
|
+
export const startTrial = mutation.mutation(async ({ ctx }) => {
|
|
76
|
+
// the caller's own id, never one the client passes in
|
|
77
|
+
const { userId } = ctx.auth;
|
|
78
|
+
if (!userId) {
|
|
79
|
+
throw new LunoraError("UNAUTHORIZED", "not signed in");
|
|
80
|
+
}
|
|
81
|
+
// run an internal action 14 days from now; the id is a plain string
|
|
82
|
+
const jobId = await ctx.scheduler.runAfter(14 * 24 * 60 * 60 * 1000, internal.billing.endTrial, { userId });
|
|
83
|
+
|
|
84
|
+
return { jobId };
|
|
47
85
|
});
|
|
48
86
|
```
|
|
49
87
|
|
|
50
|
-
- `runAfter(delayMs,
|
|
51
|
-
|
|
52
|
-
a `
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
88
|
+
- The full `ctx.scheduler` surface is `runAfter(delayMs, target, args?)`,
|
|
89
|
+
`runAt(timestampMs, target, args?)` (epoch ms), `cancel(id)`, `get(id)`, and `list()`.
|
|
90
|
+
It is not available in a `query`, because queries are deterministic and re-run.
|
|
91
|
+
- `target` is a generated `internal.*` / `api.*` mutation or action reference, a
|
|
92
|
+
`"file:fn"` string, or a `workflows.<name>` / `agents.<name>` reference.
|
|
93
|
+
A workflow or agent reference starts a fresh instance when the job fires, with
|
|
94
|
+
`args` as its params. Scheduled jobs run with no end-user identity, so target
|
|
95
|
+
`internal.*` functions.
|
|
96
|
+
- **Inside a mutation, scheduling is transactional.** The call is buffered and
|
|
97
|
+
dispatched only after the mutation commits. If the mutation rolls back (OCC
|
|
98
|
+
conflict, validation error), the job is dropped too. The returned id is final
|
|
99
|
+
immediately, so you can store it on the row you're writing and `cancel` it later.
|
|
100
|
+
- Retries use the DO defaults: 5 retries, exponential backoff from 30 s. A job
|
|
101
|
+
that exhausts them is dead-lettered (visible in the studio), not dropped. To set
|
|
102
|
+
a per-job `retry` policy (`{ maxAttempts, backoff: "exponential" | "linear",
|
|
103
|
+
baseMs, maxMs }`) or a `shardKey`, build your own client with
|
|
104
|
+
`createScheduler({ namespace })` from `@lunora/scheduler`. Its `runAfter`/`runAt`
|
|
105
|
+
take a fourth `RunOptions` argument and add `dead()` / `deadRetry(id)`.
|
|
106
|
+
|
|
107
|
+
## Recurring jobs: crons
|
|
65
108
|
|
|
66
109
|
### Step 1: Add the starter
|
|
67
110
|
|
|
68
111
|
```bash
|
|
69
112
|
lunora registry add crons
|
|
113
|
+
pnpm install
|
|
70
114
|
```
|
|
71
115
|
|
|
72
|
-
This adds `@lunora/server` to `package.json`
|
|
73
|
-
`lunora/crons.ts` (a `cronJobs()` registry
|
|
74
|
-
`lunora/crons/jobs.ts` (
|
|
75
|
-
project — both **yours** to edit. No extra DO binding is required.
|
|
116
|
+
This adds `@lunora/server` + `@lunora/scheduler` to `package.json` and copies two
|
|
117
|
+
files you own: `lunora/crons.ts` (a `cronJobs()` registry) and
|
|
118
|
+
`lunora/crons/jobs.ts` (an example `internalMutation`, `internal.crons.jobs.run`).
|
|
76
119
|
|
|
77
120
|
### Step 2: Declare jobs
|
|
78
121
|
|
|
79
122
|
```ts
|
|
80
123
|
import { cronJobs } from "@lunora/server";
|
|
81
124
|
|
|
82
|
-
import { internal } from "
|
|
125
|
+
import { internal } from "#lunora/_generated/internal.js";
|
|
83
126
|
|
|
84
127
|
const crons = cronJobs();
|
|
85
128
|
|
|
86
129
|
crons.interval("sweep presence", { minutes: 5 }, internal.presence.sweep, { roomId: "lobby" });
|
|
87
|
-
crons.
|
|
88
|
-
crons.
|
|
89
|
-
crons.
|
|
90
|
-
crons.
|
|
130
|
+
crons.hourly("rollup", { minuteUTC: 17 }, internal.stats.rollup);
|
|
131
|
+
crons.daily("digest", { hourUTC: 9, minuteUTC: 0 }, internal.email.digest);
|
|
132
|
+
crons.weekly("report", { dayOfWeek: "monday", hourUTC: 8, minuteUTC: 0 }, internal.reports.weekly);
|
|
133
|
+
crons.monthly("invoice", { day: 1, hourUTC: 0, minuteUTC: 0 }, internal.billing.invoice);
|
|
134
|
+
crons.cron("custom", "0 */6 * * *", internal.foo.bar); // raw cron escape hatch
|
|
91
135
|
|
|
92
136
|
export default crons;
|
|
93
137
|
```
|
|
94
138
|
|
|
95
|
-
-
|
|
96
|
-
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
139
|
+
- Names must be non-empty string literals, unique across the project.
|
|
140
|
+
- Targets must be static property accesses (`internal.<…path>.<fn>`, one segment
|
|
141
|
+
per folder and file, e.g. `internal.crons.jobs.run`) or a `workflows.<name>` /
|
|
142
|
+
`agents.<name>` reference. Codegen resolves them from the AST, so a computed
|
|
143
|
+
reference fails codegen. `args` is optional and must be a literal.
|
|
144
|
+
- Schedules are UTC and validated when the job is defined. `interval` takes exactly one of
|
|
145
|
+
`{ minutes }` (must divide 60) or `{ hours }` (must divide 24). `{ seconds }`
|
|
146
|
+
is rejected because Cron Triggers have a one-minute floor. For sub-minute work,
|
|
147
|
+
use `runAfter`.
|
|
148
|
+
- Use `hourly` with an offset minute to spread jobs away from `:00`.
|
|
101
149
|
|
|
102
|
-
### Step 3: Regenerate
|
|
150
|
+
### Step 3: Regenerate
|
|
103
151
|
|
|
104
152
|
```bash
|
|
105
153
|
lunora codegen
|
|
106
154
|
```
|
|
107
155
|
|
|
108
|
-
Codegen
|
|
109
|
-
|
|
110
|
-
`
|
|
111
|
-
|
|
156
|
+
Codegen emits `lunora/_generated/crons.ts` (`LUNORA_CRON_TRIGGERS` plus the
|
|
157
|
+
`LUNORA_CRONS` dispatcher map, which `defineApp` wires into `scheduled()`) and
|
|
158
|
+
syncs `triggers.crons` in `wrangler.jsonc`. Don't hand-edit that array.
|
|
159
|
+
|
|
160
|
+
**Verify:** the studio's scheduled-jobs view lists each cron and has a "Run now"
|
|
161
|
+
action, which calls the same dispatch path as a real tick.
|
|
112
162
|
|
|
113
|
-
## Bounded concurrency
|
|
163
|
+
## Bounded concurrency: workpool (optional)
|
|
114
164
|
|
|
115
|
-
|
|
116
|
-
|
|
165
|
+
A workpool is a named pool inside the same `SchedulerDO`. It needs no extra
|
|
166
|
+
binding. Build it in Worker code that has the raw `env`:
|
|
117
167
|
|
|
118
168
|
```ts
|
|
119
169
|
import { createWorkpool } from "@lunora/scheduler";
|
|
120
170
|
|
|
121
|
-
const pool = createWorkpool({
|
|
122
|
-
namespace: env.SCHEDULER,
|
|
123
|
-
originUrl: "https://my-app.example.com",
|
|
124
|
-
name: "imports",
|
|
125
|
-
maxConcurrency: 3,
|
|
126
|
-
});
|
|
171
|
+
const pool = createWorkpool({ namespace: env.SCHEDULER, name: "imports", maxConcurrency: 3 });
|
|
127
172
|
|
|
128
|
-
await pool.enqueue(internal.imports.processRow, { rowId });
|
|
173
|
+
await pool.enqueue(internal.imports.processRow, { rowId }, { retry: { maxAttempts: 3 } });
|
|
174
|
+
// pool.cancel(id), pool.status() → { inFlight, queued, maxConcurrency }
|
|
129
175
|
```
|
|
130
176
|
|
|
131
|
-
The DO
|
|
132
|
-
durably.
|
|
133
|
-
|
|
134
|
-
|
|
177
|
+
The DO dispatches at most `maxConcurrency` jobs at once and queues the rest
|
|
178
|
+
durably. One alarm drain keeps at most six dispatches in flight (the DO connection limit),
|
|
179
|
+
so a long-running job holds a slot for its whole duration. For individually long jobs
|
|
180
|
+
(LLM calls, exports), prefer `createQueueWorkpool`, which is backed by Cloudflare Queues.
|
|
181
|
+
You give up the hard cap, per-job cancel and per-job status in exchange.
|
|
135
182
|
|
|
136
183
|
## Common Pitfalls
|
|
137
184
|
|
|
138
|
-
1.
|
|
139
|
-
|
|
140
|
-
2.
|
|
141
|
-
|
|
142
|
-
3. **
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
## Checklist
|
|
148
|
-
|
|
149
|
-
- [ ] Deferred work uses `ctx.scheduler.runAfter` / `runAt` against
|
|
150
|
-
`internal.*` functions.
|
|
151
|
-
- [ ] `SCHEDULER` (SchedulerDO) binding present in `wrangler.jsonc`
|
|
152
|
-
(`lunora doctor` clean) when using the scheduler.
|
|
153
|
-
- [ ] Recurring jobs declared in `lunora/crons.ts` via `cronJobs()` (after
|
|
154
|
-
`lunora registry add crons`).
|
|
155
|
-
- [ ] `lunora codegen` run so `_generated/crons.ts` + `triggers.crons` are
|
|
156
|
-
synced.
|
|
157
|
-
- [ ] Job handlers are idempotent.
|
|
185
|
+
1. **`ORIGIN_NOT_CONFIGURED`**: `LUNORA_ORIGIN_URL` is unset for the `SchedulerDO`
|
|
186
|
+
(see above).
|
|
187
|
+
2. **`SchedulerDO` not exported** from a hand-written worker entry: wrangler
|
|
188
|
+
only binds classes the entry exports, so `SCHEDULER` is never provisioned.
|
|
189
|
+
3. **Dynamic `name` or target in `cronJobs()`**: codegen cannot discover it.
|
|
190
|
+
4. **Editing crons without re-running `lunora codegen`**: `triggers.crons` and the
|
|
191
|
+
dispatcher map are generated output and go stale.
|
|
192
|
+
5. **Non-idempotent handlers**: a failed job is retried, and a slow cron tick
|
|
193
|
+
can overlap the next one.
|