@catamorphic/work-server 0.1.0-alpha.31 → 0.1.0-alpha.33
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 +98 -38
- package/dist/auth/auth-database.d.ts +1 -0
- package/dist/auth/auth-database.d.ts.map +1 -1
- package/dist/auth/fastify-auth.d.ts.map +1 -1
- package/dist/auth/migrate-legacy-oauth.d.ts +14 -0
- package/dist/auth/migrate-legacy-oauth.d.ts.map +1 -0
- package/dist/auth/work-auth-types.d.ts +4 -0
- package/dist/auth/work-auth-types.d.ts.map +1 -1
- package/dist/auth/work-auth.d.ts +2 -0
- package/dist/auth/work-auth.d.ts.map +1 -1
- package/dist/config.d.ts +2 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +581 -324
- package/dist/index.js.map +12 -11
- package/dist/server.d.ts +4 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/test-support.d.ts +6 -0
- package/dist/test-support.d.ts.map +1 -1
- package/dist/workers/install-script.d.ts +2 -3
- package/dist/workers/install-script.d.ts.map +1 -1
- package/dist/workers/machine-rules.d.ts.map +1 -1
- package/package.json +21 -19
- package/src/auth/auth-database.ts +33 -3
- package/src/auth/fastify-auth.ts +88 -40
- package/src/auth/migrate-legacy-oauth.ts +238 -0
- package/src/auth/work-auth-types.ts +2 -0
- package/src/auth/work-auth.ts +114 -25
- package/src/config.ts +3 -10
- package/src/index.ts +5 -4
- package/src/server.ts +7 -1
- package/src/test-support.ts +51 -7
- package/src/workers/install-script.ts +4 -5
- package/src/workers/machine-rules.ts +28 -24
|
@@ -4,14 +4,13 @@ import type { FastifyInstance } from "fastify";
|
|
|
4
4
|
export interface InstallTarget {
|
|
5
5
|
/** The control plane's public origin the worker dials. */
|
|
6
6
|
controlPlaneUrl: string;
|
|
7
|
-
/** The
|
|
7
|
+
/** The deployment's explicitly selected worker image. */
|
|
8
8
|
image: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The install target, or why machines cannot install from this server: a
|
|
13
|
-
* worker image is needed (
|
|
14
|
-
* `WORK_WORKER_IMAGE`), and a public origin other machines reach.
|
|
13
|
+
* deployment-owned worker image is needed (`WORK_WORKER_IMAGE`), and a public origin other machines reach.
|
|
15
14
|
*/
|
|
16
15
|
export function installTarget(args: {
|
|
17
16
|
publicBase: string;
|
|
@@ -20,7 +19,7 @@ export function installTarget(args: {
|
|
|
20
19
|
if (!args.workerImage)
|
|
21
20
|
return {
|
|
22
21
|
unavailable:
|
|
23
|
-
"This server does not know which worker image machines should run. Set WORK_WORKER_IMAGE to
|
|
22
|
+
"This server does not know which worker image machines should run. Set WORK_WORKER_IMAGE to your deployment's pinned worker image (see @catamorphic/work-server deployment guidance).",
|
|
24
23
|
};
|
|
25
24
|
if (isLoopback(args.publicBase))
|
|
26
25
|
return {
|
|
@@ -91,7 +90,7 @@ usage() {
|
|
|
91
90
|
Usage: install.sh --code <code> [--image <image>] [--data-dir <dir>] [--name <name>] [--sandbox <backend>]
|
|
92
91
|
|
|
93
92
|
--code <code> the one-time enrollment code from the Work server (required)
|
|
94
|
-
--image <image> the worker image (default:
|
|
93
|
+
--image <image> the worker image (default: the deployment's configured worker image)
|
|
95
94
|
--data-dir <dir> where the worker keeps its credential, sandboxes and
|
|
96
95
|
members' sign-ins (default: ${DEFAULT_WORKER_DATA_DIR}): a new
|
|
97
96
|
directory, or one under /var/lib, /srv, /opt, /data or
|
|
@@ -1440,18 +1440,7 @@ export class MachineReconciler {
|
|
|
1440
1440
|
])
|
|
1441
1441
|
.where("placement_waits.tenant_id", "=", this.deps.tenantId)
|
|
1442
1442
|
.where("placement_waits.last_tried_at", ">", waitFresh())
|
|
1443
|
-
.where((
|
|
1444
|
-
exists(
|
|
1445
|
-
selectFrom("agent_turns")
|
|
1446
|
-
.select("agent_turns.id")
|
|
1447
|
-
.whereRef(
|
|
1448
|
-
"agent_turns.session_id",
|
|
1449
|
-
"=",
|
|
1450
|
-
"placement_waits.root_workload_id",
|
|
1451
|
-
)
|
|
1452
|
-
.where("agent_turns.status", "=", "queued"),
|
|
1453
|
-
),
|
|
1454
|
-
)
|
|
1443
|
+
.where(queuedPlacementWait(this.deps.db))
|
|
1455
1444
|
.orderBy("placement_waits.waiting_since")
|
|
1456
1445
|
.execute(),
|
|
1457
1446
|
this.deps.workers.machines(),
|
|
@@ -1557,18 +1546,7 @@ export class MachineReconciler {
|
|
|
1557
1546
|
)
|
|
1558
1547
|
.where("tenant_id", "=", this.deps.tenantId)
|
|
1559
1548
|
.where("last_tried_at", ">", waitFresh())
|
|
1560
|
-
.where((
|
|
1561
|
-
exists(
|
|
1562
|
-
selectFrom("agent_turns")
|
|
1563
|
-
.select("agent_turns.id")
|
|
1564
|
-
.whereRef(
|
|
1565
|
-
"agent_turns.session_id",
|
|
1566
|
-
"=",
|
|
1567
|
-
"placement_waits.root_workload_id",
|
|
1568
|
-
)
|
|
1569
|
-
.where("agent_turns.status", "=", "queued"),
|
|
1570
|
-
),
|
|
1571
|
-
)
|
|
1549
|
+
.where(queuedPlacementWait(this.deps.db))
|
|
1572
1550
|
.as("waits"),
|
|
1573
1551
|
eb
|
|
1574
1552
|
.selectFrom("execution_allocations")
|
|
@@ -1948,3 +1926,29 @@ function canonical(value: unknown): string {
|
|
|
1948
1926
|
: entry,
|
|
1949
1927
|
);
|
|
1950
1928
|
}
|
|
1929
|
+
|
|
1930
|
+
/** Both kinds of work reuse placement demand; waiting journals alone are no demand. */
|
|
1931
|
+
function queuedPlacementWait(db: Kysely<DB>) {
|
|
1932
|
+
const turns = db
|
|
1933
|
+
.selectFrom("agent_turns")
|
|
1934
|
+
.select("id")
|
|
1935
|
+
.where("session_id", "=", sql<string>`placement_waits.root_workload_id`)
|
|
1936
|
+
.where("status", "=", "queued");
|
|
1937
|
+
const jobs = db
|
|
1938
|
+
.selectFrom("workflow_runs as root")
|
|
1939
|
+
.innerJoin(
|
|
1940
|
+
"workflow_runs as run",
|
|
1941
|
+
"run.allocation_id",
|
|
1942
|
+
"root.allocation_id",
|
|
1943
|
+
)
|
|
1944
|
+
.innerJoin("execution_jobs as job", "job.workflow_run_id", "run.id")
|
|
1945
|
+
.select("job.id")
|
|
1946
|
+
.where("root.id", "=", sql<string>`placement_waits.root_workload_id`)
|
|
1947
|
+
.where("root.status", "in", ["pending", "running", "waiting"])
|
|
1948
|
+
.where("run.status", "in", ["pending", "running", "waiting"])
|
|
1949
|
+
.where("job.status", "=", "pending")
|
|
1950
|
+
.where("job.kind", "!=", "durable_pause_timeout")
|
|
1951
|
+
.where("job.available_at", "<=", sql<Date>`now()`);
|
|
1952
|
+
return sql<boolean>`((placement_waits.workload_kind = 'agent' AND EXISTS (${turns})) OR
|
|
1953
|
+
(placement_waits.workload_kind = 'workflow' AND EXISTS (${jobs})))`;
|
|
1954
|
+
}
|