@lunora/runtime 1.0.0-alpha.77 → 1.0.0-alpha.78
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/README.md +38 -0
- package/dist/index.d.mts +10 -3
- package/dist/index.d.ts +10 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -103,6 +103,44 @@ export const refreshProducts = action.action(async ({ ctx }) => {
|
|
|
103
103
|
|
|
104
104
|
The `ctx.cache` binding is only available in **action** handlers (not query/mutation), because actions run in the Worker while queries/mutations run inside the Durable Object. Cache header declarations on `httpRoute` (`.cacheControl()`, `.cacheTag()`, `.vary()`) are attached by `@lunora/server` before the response leaves the handler.
|
|
105
105
|
|
|
106
|
+
### Scheduled backups
|
|
107
|
+
|
|
108
|
+
The worker can take its own NDJSON snapshots on a Cron Trigger, writing them to an R2 bucket in your account — the same format and key layout `lunora backup list|restore` reads, so cron-written and hand-taken snapshots share one history.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
interface BackupEnv extends Env {
|
|
112
|
+
BACKUPS: R2Bucket;
|
|
113
|
+
LUNORA_ADMIN_TOKEN: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let worker: LunoraWorker | null = null;
|
|
117
|
+
|
|
118
|
+
const build = (env: BackupEnv): LunoraWorker =>
|
|
119
|
+
(worker ??= createWorker({
|
|
120
|
+
adminToken: env.LUNORA_ADMIN_TOKEN,
|
|
121
|
+
backupCron: "0 3 * * *", // must match an entry in wrangler `triggers.crons`, verbatim
|
|
122
|
+
backupRetain: 14,
|
|
123
|
+
backupStore: env.BACKUPS, // a bound R2 bucket satisfies `BackupStore`
|
|
124
|
+
queryCoordinator, // the export walks every shard through it
|
|
125
|
+
shardDO: env.SHARD,
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
export default {
|
|
129
|
+
fetch: (request: Request, env: BackupEnv, ctx: ExecutionContext) => build(env).fetch(request, env, ctx),
|
|
130
|
+
scheduled: (controller: ScheduledController, env: BackupEnv, ctx: ExecutionContext) => build(env).scheduled(controller, env, ctx),
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Five things are easy to get wrong, and four of them fail silently:
|
|
135
|
+
|
|
136
|
+
- **`scheduled` must be wired.** `createWorker` returns it, but a worker that only exports `fetch` never runs a backup, and nothing reports that.
|
|
137
|
+
- **`backupCron` is compared verbatim** against the firing expression. `"0 3 * * *"` and `"0 3 * * *"` are different strings, and the mismatch is silent — the trigger fires, no backup runs.
|
|
138
|
+
- **`backupStore`, `adminToken` and `queryCoordinator` are all required.** The snapshot is assembled by walking every shard's admin export route, so it needs the coordinator to reach them and a token to authorize itself. Missing any one throws `BACKUP_NOT_CONFIGURED` from inside the scheduled handler — the one failure here that is loud.
|
|
139
|
+
- **`backupRetain` does not delete anything.** It is a reporting window: each run logs how many snapshots sit past the newest N and tells you to run `lunora backup prune`, which is the only thing that removes a backup. A bucket therefore grows until you prune it.
|
|
140
|
+
- **The snapshot is built in memory.** It is capped at 24 MiB and refuses past it, writing nothing — narrow it with `backupTables`, or take that snapshot off-platform with `lunora backup create --bucket`.
|
|
141
|
+
|
|
142
|
+
`backupPrefix` (default `"backups/"`) sets the key prefix, and `backupTables` narrows the snapshot to an allowlist. The 24 MiB cap is smaller than the 32 MiB one on `lunora backup create --bucket`, which travels through the checksum-verified upload route instead of being held in an isolate.
|
|
143
|
+
|
|
106
144
|
## Related
|
|
107
145
|
|
|
108
146
|
- [`@lunora/do`](https://www.npmjs.com/package/@lunora/do) — the `ShardDO` / `SessionDO` Durable Objects this runtime routes to.
|
package/dist/index.d.mts
CHANGED
|
@@ -3609,9 +3609,16 @@ interface WorkerOptions {
|
|
|
3609
3609
|
*/
|
|
3610
3610
|
backupPrefix?: string;
|
|
3611
3611
|
/**
|
|
3612
|
-
* Retention
|
|
3613
|
-
*
|
|
3614
|
-
*
|
|
3612
|
+
* Retention window for scheduled backups: the newest N snapshots under
|
|
3613
|
+
* {@link WorkerOptions.backupPrefix} are the ones considered current. Omit
|
|
3614
|
+
* (or `0`) to treat every backup as current.
|
|
3615
|
+
*
|
|
3616
|
+
* **Reporting only — this never deletes.** Each run logs how many snapshots
|
|
3617
|
+
* sit past the window and points at `lunora backup prune`, which is the only
|
|
3618
|
+
* thing that removes one (and which confirms first). A bucket therefore
|
|
3619
|
+
* grows until someone prunes it. Said explicitly because the name reads like
|
|
3620
|
+
* the opposite, and because a backup deleted by a cron nobody was watching
|
|
3621
|
+
* is not a failure mode this should ever have.
|
|
3615
3622
|
*/
|
|
3616
3623
|
backupRetain?: number;
|
|
3617
3624
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -3609,9 +3609,16 @@ interface WorkerOptions {
|
|
|
3609
3609
|
*/
|
|
3610
3610
|
backupPrefix?: string;
|
|
3611
3611
|
/**
|
|
3612
|
-
* Retention
|
|
3613
|
-
*
|
|
3614
|
-
*
|
|
3612
|
+
* Retention window for scheduled backups: the newest N snapshots under
|
|
3613
|
+
* {@link WorkerOptions.backupPrefix} are the ones considered current. Omit
|
|
3614
|
+
* (or `0`) to treat every backup as current.
|
|
3615
|
+
*
|
|
3616
|
+
* **Reporting only — this never deletes.** Each run logs how many snapshots
|
|
3617
|
+
* sit past the window and points at `lunora backup prune`, which is the only
|
|
3618
|
+
* thing that removes one (and which confirms first). A bucket therefore
|
|
3619
|
+
* grows until someone prunes it. Said explicitly because the name reads like
|
|
3620
|
+
* the opposite, and because a backup deleted by a cron nobody was watching
|
|
3621
|
+
* is not a failure mode this should ever have.
|
|
3615
3622
|
*/
|
|
3616
3623
|
backupRetain?: number;
|
|
3617
3624
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/runtime",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.78",
|
|
4
4
|
"description": "Lunora Worker runtime: the RPC router, shard resolver, and query coordinator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/bindings": "1.0.0-alpha.
|
|
49
|
+
"@lunora/bindings": "1.0.0-alpha.40",
|
|
50
50
|
"@lunora/errors": "1.0.0-alpha.24",
|
|
51
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
51
|
+
"@lunora/platform": "1.0.0-alpha.19"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": "^22.15.0 || >=24.11.0"
|