@protobase/cli 0.100.19 → 0.100.20
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/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/serve/close-server.ts
|
|
2
|
+
/**
|
|
3
|
+
* How `server` closes, given before it listens so it sees every request: it stops accepting connections and resolves
|
|
4
|
+
* once every open one ended. Each request open then, and each one that comes on an open connection meanwhile, is
|
|
5
|
+
* answered with `Connection: close`, and idle connections close at once; whatever is still open after `graceMs` is
|
|
6
|
+
* dropped. Node's `close` alone waits for busy keep-alive connections, which a client that asks again as each answer
|
|
7
|
+
* comes, as a runner's long poll does, never leaves idle.
|
|
8
|
+
*/
|
|
9
|
+
const serverCloser = (server) => {
|
|
10
|
+
const open = /* @__PURE__ */ new Set();
|
|
11
|
+
let closing = false;
|
|
12
|
+
const last = (response) => {
|
|
13
|
+
if (!response.headersSent) response.setHeader("connection", "close");
|
|
14
|
+
};
|
|
15
|
+
server.on("request", (_request, response) => {
|
|
16
|
+
if (closing) last(response);
|
|
17
|
+
open.add(response);
|
|
18
|
+
response.once("close", () => open.delete(response));
|
|
19
|
+
});
|
|
20
|
+
return (graceMs) => new Promise((resolve, reject) => {
|
|
21
|
+
closing = true;
|
|
22
|
+
const dropping = setTimeout(() => server.closeAllConnections(), graceMs);
|
|
23
|
+
server.close((error) => {
|
|
24
|
+
clearTimeout(dropping);
|
|
25
|
+
if (error) reject(error);
|
|
26
|
+
else resolve();
|
|
27
|
+
});
|
|
28
|
+
for (const response of open) last(response);
|
|
29
|
+
server.closeIdleConnections();
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { serverCloser };
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -6,6 +6,7 @@ import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
|
6
6
|
import { withClientAddress } from "./client-address.js";
|
|
7
7
|
import { createServeApp } from "./app.js";
|
|
8
8
|
import { startCleanupTimer } from "./cleanup-timer.js";
|
|
9
|
+
import { serverCloser } from "./close-server.js";
|
|
9
10
|
import { closeSockets } from "./close-sockets.js";
|
|
10
11
|
import { servedRelease } from "./mobile-release.js";
|
|
11
12
|
import pg from "pg";
|
|
@@ -19,8 +20,9 @@ const listen = (server, port, host) => new Promise((resolve, reject) => {
|
|
|
19
20
|
resolve();
|
|
20
21
|
});
|
|
21
22
|
});
|
|
22
|
-
|
|
23
|
-
const
|
|
23
|
+
/** How long a closing server lets the requests open on it finish, as the jobs' shutdown lets running jobs, in ms. */
|
|
24
|
+
const closeGraceMs = 3e4;
|
|
25
|
+
const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, url, env.dbConnections), site, ui, reporter, closeGraceMs: graceMs = closeGraceMs }) => {
|
|
24
26
|
if (!env.databaseUrl) throw new Error("No database: set DATABASE_URL");
|
|
25
27
|
const database = openDb(env.databaseUrl);
|
|
26
28
|
const { db } = database;
|
|
@@ -87,12 +89,15 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
87
89
|
overrideGlobalObjects: false,
|
|
88
90
|
websocket: { server: sockets }
|
|
89
91
|
});
|
|
92
|
+
const closeServer = serverCloser(server);
|
|
90
93
|
await listen(server, env.port, env.host).catch(async (error) => {
|
|
91
94
|
await jobs?.stop();
|
|
92
95
|
throw error;
|
|
93
96
|
});
|
|
94
97
|
return {
|
|
95
98
|
server,
|
|
99
|
+
closeServer,
|
|
100
|
+
admin,
|
|
96
101
|
sockets,
|
|
97
102
|
jobs,
|
|
98
103
|
prune: admin.startRealtimePrune(),
|
|
@@ -100,7 +105,7 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
100
105
|
files: project.files
|
|
101
106
|
};
|
|
102
107
|
};
|
|
103
|
-
const { server, sockets, jobs, prune, resources, files } = await startJobsAndListen().catch(async (error) => {
|
|
108
|
+
const { server, closeServer, admin, sockets, jobs, prune, resources, files } = await startJobsAndListen().catch(async (error) => {
|
|
104
109
|
await db.destroy();
|
|
105
110
|
throw error;
|
|
106
111
|
});
|
|
@@ -111,7 +116,8 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
111
116
|
});
|
|
112
117
|
const timer = cleanup && env.filesCleanupMinutes > 0 ? startCleanupTimer(cleanup.run, env.filesCleanupMinutes, (error) => console.error(error)) : void 0;
|
|
113
118
|
const close = async () => {
|
|
114
|
-
const closed = closeServer(
|
|
119
|
+
const closed = closeServer(graceMs);
|
|
120
|
+
await admin.stopHolding();
|
|
115
121
|
await closeSockets(sockets.clients);
|
|
116
122
|
await closed;
|
|
117
123
|
await backgroundSettled();
|
|
@@ -126,4 +132,4 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
126
132
|
};
|
|
127
133
|
};
|
|
128
134
|
//#endregion
|
|
129
|
-
export { startServe };
|
|
135
|
+
export { closeGraceMs, startServe };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.100.
|
|
3
|
+
"version": "0.100.20",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.100.
|
|
47
|
-
"@protobase/layout": "0.100.
|
|
48
|
-
"@protobase/query": "0.100.
|
|
49
|
-
"@protobase/schema": "0.100.
|
|
50
|
-
"@protobase/server": "0.100.
|
|
51
|
-
"@protobase/ui": "0.100.
|
|
52
|
-
"@protobase/workflows": "0.100.
|
|
46
|
+
"@protobase/config": "0.100.20",
|
|
47
|
+
"@protobase/layout": "0.100.20",
|
|
48
|
+
"@protobase/query": "0.100.20",
|
|
49
|
+
"@protobase/schema": "0.100.20",
|
|
50
|
+
"@protobase/server": "0.100.20",
|
|
51
|
+
"@protobase/ui": "0.100.20",
|
|
52
|
+
"@protobase/workflows": "0.100.20",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -470,7 +470,7 @@ The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless i
|
|
|
470
470
|
- **Manifest:** a config module needs its `protobase.bundle.json` beside it. The runtime checks no version: the host picks the runtime from the manifest's `protobase` (see [Versioning](versioning.md#bundles-and-runtimes)).
|
|
471
471
|
- **Startup:** a config module that `protobase build` did not write, a config with an `apiPath` other than `/api/v1`, or one with sign-in on and no secret or URL, stops startup with a one-line error and exit code 1, as does a missing `DATABASE_URL`, an auth store that has not applied every migration of this version, or has a newer one (see [`auth migration`](#auth-migration)), a resource over a table of the auth store, a resource whose [events](events.md) or [history](history.md) lack their triggers or have out-of-date ones, or a missing history or [comments](comments.md#the-table) table, a [rollup or formula field](data-config.md#rollups-and-formulas) whose column or trigger is missing or out of date, a jobs schema that is missing or behind for a config with [jobs](jobs.md#the-jobs-schema) (see [`migration`](#migration)), an [AI field or action](ai.md#the-model) without a model key, [encrypted fields](data-config.md#encrypted-fields) without a key, or another resource over their column, or a taken port; `PROTOBASE_STARTUP_CHECKS=false` skips the checks of those schemas and the key. `protobase serve listening on port <port>` means it is ready.
|
|
472
472
|
- **Jobs:** with [jobs](jobs.md) in the config it runs them beside the API, unless `PROTOBASE_JOBS=false`, and with `PROTOBASE_JOBS_DRAIN_TOKEN` it answers `POST /api/jobs/drain` for the operator.
|
|
473
|
-
- **Shutdown:** the first SIGTERM or SIGINT stops accepting connections, closes open WebSockets with 1001 (dropping any still open after 5 seconds), waits for open requests, gives running jobs 30 seconds to finish, drains the pool `serve` created and exits with 0.
|
|
473
|
+
- **Shutdown:** the first SIGTERM or SIGINT stops accepting connections, answers the requests held open waiting at once (a [runner's](workflows.md#runners) claim gets no job), closes open WebSockets with 1001 (dropping any still open after 5 seconds), and waits for open requests, answering each with `Connection: close` so a client that polls on a kept-alive connection asks no more of this process; a request still open after 30 seconds has its connection dropped. It then gives running jobs 30 seconds to finish, drains the pool `serve` created and exits with 0.
|
|
474
474
|
- **Host modules:** under Bun, the runtime registers [the modules it supplies](#the-config-module) as virtual modules, so the bundle needs no `node_modules` for them. `protobase serve` and `protobase worker` under Bun do the same with the CLI's own copies, whatever the project installed, so a bundle runs on the copies of the CLI that runs it. <gap>`protobase serve` and `protobase worker` on Node cannot give a bundle the CLI's own host modules because a module hook for Node is not implemented.</gap> On Node both resolve them from the `node_modules` next to the bundle, so there keep the bundle inside the project, whose installed versions it then runs on. Native packages load from the bundle's own `node_modules/` under both.
|
|
475
475
|
- **Read-only hosts:** nothing is written: no install (`--no-install`), and for a bundle built with `--bun` no transpiling and so no transpiler cache. A bundle with `node_modules/` needs its folder mounted without `noexec`, since its add-ons are mapped as executable code.
|
|
476
476
|
|
|
@@ -730,7 +730,7 @@ Every other call carries the runner's own token as `Authorization: Bearer pbr_..
|
|
|
730
730
|
|
|
731
731
|
| Call | Body | Answer |
|
|
732
732
|
| --- | --- | --- |
|
|
733
|
-
| `POST /api/runners/v1/claim` | What the runner says of itself: `{ "platform": "linux/amd64", "kinds": ["container", "build"], "labels": [], "capacity": { "slots": 2 }, "images": [{ "step": "custom:ocr:4", "snapshot": true }], "instances": [{ "step": "custom:ocr:4", "free": 3 }] }` | Held open up to 50 seconds until a job is placed with the runner: `{ "order": "job", "job": { "id", "step", "input", "deadline", "heartbeat_seconds", "lease_seconds", "files", "output_files", "build", "command" } }`; `{ "order": "prepare", "step", "build" }`; or `{ "order": "none" }` when its time ran out. Claim again at once. |
|
|
733
|
+
| `POST /api/runners/v1/claim` | What the runner says of itself: `{ "platform": "linux/amd64", "kinds": ["container", "build"], "labels": [], "capacity": { "slots": 2 }, "images": [{ "step": "custom:ocr:4", "snapshot": true }], "instances": [{ "step": "custom:ocr:4", "free": 3 }] }` | Held open up to 50 seconds until a job is placed with the runner: `{ "order": "job", "job": { "id", "step", "input", "deadline", "heartbeat_seconds", "lease_seconds", "files", "output_files", "build", "command" } }`; `{ "order": "prepare", "step", "build" }`; or `{ "order": "none" }` when its time ran out or the process serving it stops, which ends the connection after it. Claim again at once. |
|
|
734
734
|
| `POST /api/runners/v1/jobs/<id>/heartbeat` | `{}` | `{ "stop": false }`, extending the runner's hold of the job and counting as a heartbeat of its Task; `{ "stop": true }` once the runner no longer holds it, as when its try timed out, its run ended or its lease ran out: stop the job. |
|
|
735
735
|
| `POST /api/runners/v1/jobs/<id>/log` | `{ "lines": ["..."] }`, at most 100 | `{}`; the job keeps its last 100 lines, each up to 1,000 characters, with the workflows' secrets and the token blanked out. |
|
|
736
736
|
| `GET /api/runners/v1/jobs/<id>/inputs/<input>` | | The bytes of the job's input file `<input>`, streamed from its storage configuration or the run's files. |
|