@caelo-cms/provisioning 0.10.53 → 0.10.57
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/agent-db.js +272 -128
- package/dist/audit-job-setup.d.ts +69 -0
- package/dist/audit-job-setup.d.ts.map +1 -0
- package/dist/audit-job-setup.js +317 -0
- package/dist/audit-job-setup.js.map +1 -0
- package/dist/caddy.d.ts +9 -0
- package/dist/caddy.d.ts.map +1 -1
- package/dist/caddy.js +38 -0
- package/dist/caddy.js.map +1 -1
- package/dist/cli-routing.js +1 -1
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +36 -9
- package/dist/cli.js.map +1 -1
- package/dist/compose.js +5 -0
- package/dist/compose.js.map +1 -1
- package/dist/converge-checkpoint.d.ts +66 -0
- package/dist/converge-checkpoint.d.ts.map +1 -0
- package/dist/converge-checkpoint.js +61 -0
- package/dist/converge-checkpoint.js.map +1 -0
- package/dist/converge-job-gcp.d.ts +46 -0
- package/dist/converge-job-gcp.d.ts.map +1 -0
- package/dist/converge-job-gcp.js +368 -0
- package/dist/converge-job-gcp.js.map +1 -0
- package/dist/converge-job-setup.d.ts +62 -0
- package/dist/converge-job-setup.d.ts.map +1 -0
- package/dist/converge-job-setup.js +228 -0
- package/dist/converge-job-setup.js.map +1 -0
- package/dist/converge-job.d.ts +141 -0
- package/dist/converge-job.d.ts.map +1 -0
- package/dist/converge-job.js +325 -0
- package/dist/converge-job.js.map +1 -0
- package/dist/gcp-names.d.ts +25 -1
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +36 -0
- package/dist/gcp-names.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +28 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/install-job.d.ts +11 -3
- package/dist/install-job.d.ts.map +1 -1
- package/dist/install-job.js +22 -12
- package/dist/install-job.js.map +1 -1
- package/dist/lifecycle.d.ts +13 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +115 -58
- package/dist/lifecycle.js.map +1 -1
- package/dist/operator-access.d.ts.map +1 -1
- package/dist/operator-access.js +13 -3
- package/dist/operator-access.js.map +1 -1
- package/dist/private-file.d.ts +26 -0
- package/dist/private-file.d.ts.map +1 -0
- package/dist/private-file.js +49 -0
- package/dist/private-file.js.map +1 -0
- package/dist/release-contract.d.ts +3 -2
- package/dist/release-contract.d.ts.map +1 -1
- package/dist/release-contract.js +8 -2
- package/dist/release-contract.js.map +1 -1
- package/dist/release-manifest.d.ts +2 -0
- package/dist/release-manifest.d.ts.map +1 -1
- package/dist/release-manifest.js.map +1 -1
- package/dist/remote-mcp-edge.d.ts +114 -0
- package/dist/remote-mcp-edge.d.ts.map +1 -0
- package/dist/remote-mcp-edge.js +116 -0
- package/dist/remote-mcp-edge.js.map +1 -0
- package/dist/remote-mcp.d.ts +117 -0
- package/dist/remote-mcp.d.ts.map +1 -0
- package/dist/remote-mcp.js +379 -0
- package/dist/remote-mcp.js.map +1 -0
- package/dist/runtime-secrets.d.ts +12 -0
- package/dist/runtime-secrets.d.ts.map +1 -1
- package/dist/runtime-secrets.js +32 -4
- package/dist/runtime-secrets.js.map +1 -1
- package/dist/seal-key-rotation.d.ts +38 -0
- package/dist/seal-key-rotation.d.ts.map +1 -0
- package/dist/seal-key-rotation.js +206 -0
- package/dist/seal-key-rotation.js.map +1 -0
- package/dist/stack-contract.d.ts +175 -3
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +183 -3
- package/dist/stack-contract.js.map +1 -1
- package/dist/stack-converge.d.ts +38 -1
- package/dist/stack-converge.d.ts.map +1 -1
- package/dist/stack-converge.js +74 -4
- package/dist/stack-converge.js.map +1 -1
- package/dist/state-lock-lease.d.ts +142 -0
- package/dist/state-lock-lease.d.ts.map +1 -0
- package/dist/state-lock-lease.js +347 -0
- package/dist/state-lock-lease.js.map +1 -0
- package/dist/state-store.d.ts +66 -9
- package/dist/state-store.d.ts.map +1 -1
- package/dist/state-store.js +249 -30
- package/dist/state-store.js.map +1 -1
- package/dist/tar-entries.d.ts.map +1 -1
- package/dist/tar-entries.js +84 -9
- package/dist/tar-entries.js.map +1 -1
- package/dist/upgrade/app-roll.d.ts +36 -7
- package/dist/upgrade/app-roll.d.ts.map +1 -1
- package/dist/upgrade/app-roll.js +88 -19
- package/dist/upgrade/app-roll.js.map +1 -1
- package/dist/upgrade/audit-job-roll.d.ts +38 -0
- package/dist/upgrade/audit-job-roll.d.ts.map +1 -0
- package/dist/upgrade/audit-job-roll.js +43 -0
- package/dist/upgrade/audit-job-roll.js.map +1 -0
- package/dist/upgrade/converge.d.ts.map +1 -1
- package/dist/upgrade/converge.js +141 -8
- package/dist/upgrade/converge.js.map +1 -1
- package/dist/upgrade/gcp-lookup.d.ts +27 -10
- package/dist/upgrade/gcp-lookup.d.ts.map +1 -1
- package/dist/upgrade/gcp-lookup.js +46 -7
- package/dist/upgrade/gcp-lookup.js.map +1 -1
- package/dist/upgrade/record-rolled.d.ts +40 -0
- package/dist/upgrade/record-rolled.d.ts.map +1 -0
- package/dist/upgrade/record-rolled.js +46 -0
- package/dist/upgrade/record-rolled.js.map +1 -0
- package/dist/upgrade/upgrade.d.ts +45 -1
- package/dist/upgrade/upgrade.d.ts.map +1 -1
- package/dist/upgrade/upgrade.js +60 -17
- package/dist/upgrade/upgrade.js.map +1 -1
- package/dist/upgrader-assess.d.ts +15 -1
- package/dist/upgrader-assess.d.ts.map +1 -1
- package/dist/upgrader-assess.js +36 -6
- package/dist/upgrader-assess.js.map +1 -1
- package/dist/upgrader-gcp.d.ts +15 -0
- package/dist/upgrader-gcp.d.ts.map +1 -1
- package/dist/upgrader-gcp.js +42 -7
- package/dist/upgrader-gcp.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts +123 -0
- package/dist/upgrader-iam-preflight.d.ts.map +1 -0
- package/dist/upgrader-iam-preflight.js +414 -0
- package/dist/upgrader-iam-preflight.js.map +1 -0
- package/dist/upgrader-job.d.ts +33 -9
- package/dist/upgrader-job.d.ts.map +1 -1
- package/dist/upgrader-job.js +169 -27
- package/dist/upgrader-job.js.map +1 -1
- package/dist/upgrader-records.d.ts +58 -0
- package/dist/upgrader-records.d.ts.map +1 -0
- package/dist/upgrader-records.js +87 -0
- package/dist/upgrader-records.js.map +1 -0
- package/dist/upgrader-reporter.d.ts +3 -2
- package/dist/upgrader-reporter.d.ts.map +1 -1
- package/dist/upgrader-reporter.js +10 -2
- package/dist/upgrader-reporter.js.map +1 -1
- package/dist/upgrader-setup.d.ts +25 -3
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +132 -14
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +14 -6
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/dist/wizards/gcp-pulumi.d.ts +6 -0
- package/dist/wizards/gcp-pulumi.d.ts.map +1 -1
- package/dist/wizards/gcp-pulumi.js +7 -0
- package/dist/wizards/gcp-pulumi.js.map +1 -1
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +130 -4
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +4 -4
- package/src/agent/run.test.ts +15 -1
- package/src/audit-job-setup.test.ts +234 -0
- package/src/audit-job-setup.ts +360 -0
- package/src/caddy-redirects.docker.test.ts +19 -6
- package/src/caddy.test.ts +30 -0
- package/src/caddy.ts +43 -0
- package/src/cli-init-validation.test.ts +44 -0
- package/src/cli-routing.ts +1 -1
- package/src/cli.ts +40 -8
- package/src/compose.ts +5 -0
- package/src/converge-checkpoint.ts +75 -0
- package/src/converge-entrypoint.test.ts +213 -0
- package/src/converge-job-gcp.test.ts +222 -0
- package/src/converge-job-gcp.ts +443 -0
- package/src/converge-job-setup.test.ts +152 -0
- package/src/converge-job-setup.ts +268 -0
- package/src/converge-job.test.ts +486 -0
- package/src/converge-job.ts +542 -0
- package/src/gateway-env-isolation.test.ts +8 -1
- package/src/gcp-names.ts +43 -1
- package/src/gcp-url-map.test.ts +9 -1
- package/src/index.ts +8 -0
- package/src/infra-contract.test.ts +7 -4
- package/src/infra-contract.ts +28 -1
- package/src/install-job.test.ts +3 -1
- package/src/install-job.ts +31 -14
- package/src/lifecycle.ts +137 -71
- package/src/operator-access.test.ts +14 -0
- package/src/operator-access.ts +13 -3
- package/src/private-file.test.ts +80 -0
- package/src/private-file.ts +50 -0
- package/src/release-contract.ts +8 -2
- package/src/release-manifest.test.ts +42 -0
- package/src/release-manifest.ts +2 -0
- package/src/remote-mcp-edge.ts +137 -0
- package/src/remote-mcp.test.ts +517 -0
- package/src/remote-mcp.ts +460 -0
- package/src/runtime-secrets.test.ts +31 -6
- package/src/runtime-secrets.ts +41 -3
- package/src/seal-key-rotation.test.ts +131 -0
- package/src/seal-key-rotation.ts +258 -0
- package/src/stack-contract-parity.test.ts +20 -3
- package/src/stack-contract.test.ts +34 -2
- package/src/stack-contract.ts +305 -3
- package/src/stack-converge-secrets.test.ts +3 -0
- package/src/stack-converge.test.ts +21 -5
- package/src/stack-converge.ts +101 -7
- package/src/state-attach.test.ts +7 -1
- package/src/state-lock-lease.test.ts +302 -0
- package/src/state-lock-lease.ts +423 -0
- package/src/state-lock.test.ts +568 -0
- package/src/state-store.ts +347 -27
- package/src/tar-entries.test.ts +149 -7
- package/src/tar-entries.ts +90 -9
- package/src/upgrade/app-roll.ts +135 -21
- package/src/upgrade/audit-job-roll.ts +68 -0
- package/src/upgrade/converge.ts +170 -7
- package/src/upgrade/gcp-lookup.test.ts +80 -0
- package/src/upgrade/gcp-lookup.ts +65 -8
- package/src/upgrade/record-rolled.test.ts +105 -0
- package/src/upgrade/record-rolled.ts +91 -0
- package/src/upgrade/upgrade.test.ts +279 -5
- package/src/upgrade/upgrade.ts +120 -24
- package/src/upgrader-assess.test.ts +93 -3
- package/src/upgrader-assess.ts +58 -9
- package/src/upgrader-gcp.ts +47 -8
- package/src/upgrader-iam-preflight.test.ts +393 -0
- package/src/upgrader-iam-preflight.ts +510 -0
- package/src/upgrader-job.test.ts +587 -15
- package/src/upgrader-job.ts +237 -53
- package/src/upgrader-records.ts +151 -0
- package/src/upgrader-reporter.test.ts +6 -0
- package/src/upgrader-reporter.ts +7 -2
- package/src/upgrader-setup.test.ts +4 -3
- package/src/upgrader-setup.ts +137 -13
- package/src/wizards/gcp-cost.ts +15 -6
- package/src/wizards/gcp-pulumi.ts +7 -0
- package/src/wizards/gcp.ts +162 -4
- package/stacks/aws/index.ts +18 -0
- package/stacks/azure/index.ts +18 -0
- package/stacks/gcp/index.ts +59 -7
- package/stacks/gcp-firebase/index.ts +50 -6
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { GcloudResult } from "./gcloud.js";
|
|
3
|
+
/** A Cloud Run job execution, fully addressed. */
|
|
4
|
+
export interface CloudRunExecutionRef {
|
|
5
|
+
readonly projectId: string;
|
|
6
|
+
readonly region: string;
|
|
7
|
+
/** The execution's short name (`CLOUD_RUN_EXECUTION`). */
|
|
8
|
+
readonly name: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A lock holder that Cloud Run can vouch for: the execution and the
|
|
12
|
+
* longest it can run (its task timeout).
|
|
13
|
+
*/
|
|
14
|
+
export interface ExecutionLockHolder {
|
|
15
|
+
readonly execution: CloudRunExecutionRef;
|
|
16
|
+
readonly maxRuntimeMs: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A lock holder outside Cloud Run (a CLI process): its lease is short and
|
|
20
|
+
* renewed by a heartbeat while it runs, so a holder that dies stops
|
|
21
|
+
* renewing and its lock expires on its own (#815).
|
|
22
|
+
*/
|
|
23
|
+
export interface ProcessLockHolder {
|
|
24
|
+
readonly leaseMs: number;
|
|
25
|
+
}
|
|
26
|
+
/** Who takes a lock: a Cloud Run execution, or a renewing process. */
|
|
27
|
+
export type LockHolder = ExecutionLockHolder | ProcessLockHolder;
|
|
28
|
+
/** The lease of a CLI process's lock; renewed every third of it. */
|
|
29
|
+
export declare const PROCESS_LEASE_MS: number;
|
|
30
|
+
/**
|
|
31
|
+
* Margin added to a lease for clock skew between the holder and the run
|
|
32
|
+
* judging it (both read their own clock; Cloud Run's are NTP-synced, a
|
|
33
|
+
* developer laptop's may not be).
|
|
34
|
+
*/
|
|
35
|
+
export declare const LEASE_SKEW_MS: number;
|
|
36
|
+
/** The lock object's body. `execution` + `leaseUntil` appear together (#815). */
|
|
37
|
+
declare const lockBodySchema: z.ZodObject<{
|
|
38
|
+
purpose: z.ZodString;
|
|
39
|
+
id: z.ZodOptional<z.ZodString>;
|
|
40
|
+
host: z.ZodOptional<z.ZodString>;
|
|
41
|
+
machine: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
pid: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
startedAt: z.ZodOptional<z.ZodString>;
|
|
44
|
+
execution: z.ZodOptional<z.ZodObject<{
|
|
45
|
+
projectId: z.ZodString;
|
|
46
|
+
region: z.ZodString;
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
}, z.core.$strip>>;
|
|
49
|
+
leaseUntil: z.ZodOptional<z.ZodString>;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
/** The lock body as written by {@link lockBody}. */
|
|
52
|
+
export type LockBody = z.infer<typeof lockBodySchema>;
|
|
53
|
+
/**
|
|
54
|
+
* The body a new lock is written with.
|
|
55
|
+
*
|
|
56
|
+
* @param holder a Cloud Run execution (lease: `now + maxRuntimeMs +
|
|
57
|
+
* LEASE_SKEW_MS`) or a renewing process (lease: `now + leaseMs +
|
|
58
|
+
* LEASE_SKEW_MS`); none only for the machine-local lock file, which is
|
|
59
|
+
* judged by its pid alone
|
|
60
|
+
* @param id the acquisition's id; a fresh one when omitted
|
|
61
|
+
*/
|
|
62
|
+
export declare function lockBody(purpose: string, now: Date, holder?: LockHolder, id?: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* The same lock body with its lease moved to `now + leaseMs + skew` — the
|
|
65
|
+
* heartbeat of a process holder. Everything else (id, start) is kept.
|
|
66
|
+
*/
|
|
67
|
+
export declare function renewedLockBody(body: LockBody, now: Date, leaseMs: number): string;
|
|
68
|
+
/** Whether process `pid` exists on this host (signal 0 checks without signalling). */
|
|
69
|
+
export declare function processAlive(pid: number): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* An id for this machine AND pid namespace, so a pid is only ever checked
|
|
72
|
+
* where it was taken: the host name, the network cards' MAC addresses and
|
|
73
|
+
* (on Linux) the pid namespace. Null inside Cloud Run, where every
|
|
74
|
+
* container is called `localhost`, has its own pid space and no stable
|
|
75
|
+
* hardware to tell it apart — a lock from there is judged by its lease
|
|
76
|
+
* alone. Null too when the machine shows no network card. An id that
|
|
77
|
+
* changes while a lock is held (a new network card) only makes a later
|
|
78
|
+
* judge wait for the lease: a mismatch is always the safe direction.
|
|
79
|
+
*/
|
|
80
|
+
export declare function machineId(env?: NodeJS.ProcessEnv): string | null;
|
|
81
|
+
/** The judging run's own host and how it checks a local pid. */
|
|
82
|
+
export interface LocalHost {
|
|
83
|
+
readonly host: string;
|
|
84
|
+
/**
|
|
85
|
+
* {@link machineId}; a lock that names another (or none) is never judged
|
|
86
|
+
* by its pid. Left out only by a lock from before the machine id, which
|
|
87
|
+
* falls back to comparing host names (state-lock-lease tests).
|
|
88
|
+
*/
|
|
89
|
+
readonly machine?: string | null;
|
|
90
|
+
readonly alive: (pid: number) => boolean;
|
|
91
|
+
}
|
|
92
|
+
/** Parse a lock body; null when it is not one this code wrote. */
|
|
93
|
+
export declare function parseLockBody(text: string): LockBody | null;
|
|
94
|
+
/** What Cloud Run says about the holder's execution. */
|
|
95
|
+
export type ExecutionState = {
|
|
96
|
+
readonly kind: "running";
|
|
97
|
+
} | {
|
|
98
|
+
readonly kind: "finished";
|
|
99
|
+
readonly how: string;
|
|
100
|
+
} | {
|
|
101
|
+
readonly kind: "not-found";
|
|
102
|
+
}
|
|
103
|
+
/** Cloud Run could not be asked; `error` says why. */
|
|
104
|
+
| {
|
|
105
|
+
readonly kind: "unknown";
|
|
106
|
+
readonly error: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Read an execution's state from `gcloud run jobs executions describe
|
|
110
|
+
* --format=json`. An execution has finished once Cloud Run stamped its
|
|
111
|
+
* completion time or decided its `Completed` condition (True: succeeded;
|
|
112
|
+
* False: failed or cancelled). Anything else is still running — including
|
|
113
|
+
* an execution Cloud Run has not started yet.
|
|
114
|
+
*/
|
|
115
|
+
export declare function parseExecutionState(result: GcloudResult): ExecutionState;
|
|
116
|
+
/** `gcloud run jobs executions describe`, for {@link judgeHeldLock}. */
|
|
117
|
+
export declare function describeExecutionArgs(ref: CloudRunExecutionRef): string[];
|
|
118
|
+
/** Whether a held lock may be broken, and the words for either outcome. */
|
|
119
|
+
export type LockVerdict = {
|
|
120
|
+
readonly kind: "break";
|
|
121
|
+
readonly why: string;
|
|
122
|
+
} | {
|
|
123
|
+
readonly kind: "held";
|
|
124
|
+
readonly why: string;
|
|
125
|
+
readonly manualRemoval: boolean;
|
|
126
|
+
}
|
|
127
|
+
/** The holder could not be checked; never treated as "dead". */
|
|
128
|
+
| {
|
|
129
|
+
readonly kind: "unknown";
|
|
130
|
+
readonly why: string;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Decide whether the lock with body `text` may be broken.
|
|
134
|
+
*
|
|
135
|
+
* @param describe looks the holder's execution up in Cloud Run; called only
|
|
136
|
+
* when the body names one
|
|
137
|
+
* @param now the judging run's clock, compared against the lease
|
|
138
|
+
* @param here this host's name and pid check, for a process holder's lock
|
|
139
|
+
*/
|
|
140
|
+
export declare function judgeHeldLock(text: string, describe: (ref: CloudRunExecutionRef) => ExecutionState, now: Date, here?: LocalHost): LockVerdict;
|
|
141
|
+
export {};
|
|
142
|
+
//# sourceMappingURL=state-lock-lease.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-lock-lease.d.ts","sourceRoot":"","sources":["../src/state-lock-lease.ts"],"names":[],"mappings":"AAgDA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,kDAAkD;AAClD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,sEAAsE;AACtE,MAAM,MAAM,UAAU,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAEjE,oEAAoE;AACpE,eAAO,MAAM,gBAAgB,QAAc,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,aAAa,QAAa,CAAC;AAQxC,iFAAiF;AACjF,QAAA,MAAM,cAAc;;;;;;;;;;;;;iBAWlB,CAAC;AAEH,oDAAoD;AACpD,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,IAAI,EACT,MAAM,CAAC,EAAE,UAAU,EACnB,EAAE,GAAE,MAAqB,GACxB,MAAM,CAeR;AAED;;;GAGG;A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I,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAA;CAAE;AAClF,gEAAgE;GAC9D;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,cAAc,EACvD,GAAG,EAAE,IAAI,EACT,IAAI,GAAE,SAAqB,GAC1B,WAAW,CA8Cb"}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
/**
|
|
3
|
+
* The lease on the install's bucket state lock (#815): who holds it, and
|
|
4
|
+
* whether a later run may break it.
|
|
5
|
+
*
|
|
6
|
+
* A lock written by a Cloud Run job execution (the upgrader job, later the
|
|
7
|
+
* converge job #819) names that execution and a lease: the execution's
|
|
8
|
+
* start plus its task timeout, after which Cloud Run has killed it for
|
|
9
|
+
* sure. A run that finds the lock held asks Cloud Run about the holder:
|
|
10
|
+
*
|
|
11
|
+
* - the execution has finished (succeeded, failed, cancelled): it can no
|
|
12
|
+
* longer write, so its lock is dead and may be broken;
|
|
13
|
+
* - it is still running: the lock is live and is NEVER broken — not even
|
|
14
|
+
* past its lease (a lease is our estimate; Cloud Run's state is fact);
|
|
15
|
+
* - Cloud Run does not know it (deleted, or a name we cannot resolve):
|
|
16
|
+
* broken only once the lease has expired, when no execution of that
|
|
17
|
+
* job can still be alive;
|
|
18
|
+
* - Cloud Run cannot be asked (no access, gcloud error): not decided
|
|
19
|
+
* here — the caller reports the error; guessing "dead" could let two
|
|
20
|
+
* runs write the same state.
|
|
21
|
+
*
|
|
22
|
+
* A lock taken by a process outside Cloud Run (a CLI run on someone's
|
|
23
|
+
* machine or in Cloud Shell) names its host and pid and carries a short
|
|
24
|
+
* lease that the holder renews while it runs (the heartbeat in
|
|
25
|
+
* state-store.ts). Such a lock is broken when:
|
|
26
|
+
*
|
|
27
|
+
* - it was taken on THIS machine and its pid is no longer alive (a
|
|
28
|
+
* killed CLI on the same machine — no need to wait for the lease). The
|
|
29
|
+
* machine is told apart by {@link machineId}, not by its host name
|
|
30
|
+
* alone: every Cloud Run container calls itself the same, and two
|
|
31
|
+
* laptops may too, so a pid that is dead HERE says nothing about a
|
|
32
|
+
* process THERE. Inside Cloud Run there is no machine id at all, so a
|
|
33
|
+
* lock from there is only ever judged by its lease; or
|
|
34
|
+
* - its lease has expired: the holder stopped renewing it (killed, or a
|
|
35
|
+
* closed Cloud Shell), so it can no longer be writing.
|
|
36
|
+
*
|
|
37
|
+
* Only a lock written before #815 (no lease, no execution) is never broken
|
|
38
|
+
* automatically; its holder message names the command to remove it.
|
|
39
|
+
*
|
|
40
|
+
* Everything here is pure except {@link describeExecution}, which takes a
|
|
41
|
+
* {@link SyncGcloud}; the lock itself (create, generation-matched break,
|
|
42
|
+
* release) lives in state-store.ts.
|
|
43
|
+
*/
|
|
44
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
45
|
+
import { readlinkSync } from "node:fs";
|
|
46
|
+
import { hostname, networkInterfaces } from "node:os";
|
|
47
|
+
import { z } from "zod";
|
|
48
|
+
/** The lease of a CLI process's lock; renewed every third of it. */
|
|
49
|
+
export const PROCESS_LEASE_MS = 10 * 60_000;
|
|
50
|
+
/**
|
|
51
|
+
* Margin added to a lease for clock skew between the holder and the run
|
|
52
|
+
* judging it (both read their own clock; Cloud Run's are NTP-synced, a
|
|
53
|
+
* developer laptop's may not be).
|
|
54
|
+
*/
|
|
55
|
+
export const LEASE_SKEW_MS = 5 * 60_000;
|
|
56
|
+
const executionRefSchema = z.object({
|
|
57
|
+
projectId: z.string().min(1),
|
|
58
|
+
region: z.string().min(1),
|
|
59
|
+
name: z.string().min(1),
|
|
60
|
+
});
|
|
61
|
+
/** The lock object's body. `execution` + `leaseUntil` appear together (#815). */
|
|
62
|
+
const lockBodySchema = z.object({
|
|
63
|
+
purpose: z.string(),
|
|
64
|
+
/** Unique per acquisition: proves a lock is still the one this run took. */
|
|
65
|
+
id: z.string().optional(),
|
|
66
|
+
host: z.string().optional(),
|
|
67
|
+
/** {@link machineId} of the writer; null when it has none (Cloud Run). */
|
|
68
|
+
machine: z.string().nullable().optional(),
|
|
69
|
+
pid: z.number().optional(),
|
|
70
|
+
startedAt: z.string().optional(),
|
|
71
|
+
execution: executionRefSchema.optional(),
|
|
72
|
+
leaseUntil: z.string().optional(),
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* The body a new lock is written with.
|
|
76
|
+
*
|
|
77
|
+
* @param holder a Cloud Run execution (lease: `now + maxRuntimeMs +
|
|
78
|
+
* LEASE_SKEW_MS`) or a renewing process (lease: `now + leaseMs +
|
|
79
|
+
* LEASE_SKEW_MS`); none only for the machine-local lock file, which is
|
|
80
|
+
* judged by its pid alone
|
|
81
|
+
* @param id the acquisition's id; a fresh one when omitted
|
|
82
|
+
*/
|
|
83
|
+
export function lockBody(purpose, now, holder, id = randomUUID()) {
|
|
84
|
+
const leaseMs = holder ? ("execution" in holder ? holder.maxRuntimeMs : holder.leaseMs) : null;
|
|
85
|
+
const body = {
|
|
86
|
+
purpose,
|
|
87
|
+
id,
|
|
88
|
+
host: THIS_HOST.host,
|
|
89
|
+
machine: THIS_HOST.machine ?? null,
|
|
90
|
+
pid: process.pid,
|
|
91
|
+
startedAt: now.toISOString(),
|
|
92
|
+
...(holder && "execution" in holder ? { execution: { ...holder.execution } } : {}),
|
|
93
|
+
...(leaseMs !== null
|
|
94
|
+
? { leaseUntil: new Date(now.getTime() + leaseMs + LEASE_SKEW_MS).toISOString() }
|
|
95
|
+
: {}),
|
|
96
|
+
};
|
|
97
|
+
return JSON.stringify(body);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The same lock body with its lease moved to `now + leaseMs + skew` — the
|
|
101
|
+
* heartbeat of a process holder. Everything else (id, start) is kept.
|
|
102
|
+
*/
|
|
103
|
+
export function renewedLockBody(body, now, leaseMs) {
|
|
104
|
+
return JSON.stringify({
|
|
105
|
+
...body,
|
|
106
|
+
leaseUntil: new Date(now.getTime() + leaseMs + LEASE_SKEW_MS).toISOString(),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** Whether process `pid` exists on this host (signal 0 checks without signalling). */
|
|
110
|
+
export function processAlive(pid) {
|
|
111
|
+
try {
|
|
112
|
+
process.kill(pid, 0);
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
// EPERM: it exists, it is just someone else's.
|
|
117
|
+
return e.code === "EPERM";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* An id for this machine AND pid namespace, so a pid is only ever checked
|
|
122
|
+
* where it was taken: the host name, the network cards' MAC addresses and
|
|
123
|
+
* (on Linux) the pid namespace. Null inside Cloud Run, where every
|
|
124
|
+
* container is called `localhost`, has its own pid space and no stable
|
|
125
|
+
* hardware to tell it apart — a lock from there is judged by its lease
|
|
126
|
+
* alone. Null too when the machine shows no network card. An id that
|
|
127
|
+
* changes while a lock is held (a new network card) only makes a later
|
|
128
|
+
* judge wait for the lease: a mismatch is always the safe direction.
|
|
129
|
+
*/
|
|
130
|
+
export function machineId(env = process.env) {
|
|
131
|
+
if (env.CLOUD_RUN_EXECUTION || env.K_SERVICE)
|
|
132
|
+
return null;
|
|
133
|
+
const macs = new Set();
|
|
134
|
+
for (const cards of Object.values(networkInterfaces())) {
|
|
135
|
+
for (const card of cards ?? []) {
|
|
136
|
+
if (!card.internal && card.mac && card.mac !== "00:00:00:00:00:00")
|
|
137
|
+
macs.add(card.mac);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (macs.size === 0)
|
|
141
|
+
return null;
|
|
142
|
+
let pidSpace = "";
|
|
143
|
+
try {
|
|
144
|
+
pidSpace = readlinkSync("/proc/self/ns/pid");
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// Not Linux: the machine has one pid space, which the MACs already name.
|
|
148
|
+
}
|
|
149
|
+
return createHash("sha256")
|
|
150
|
+
.update([hostname(), pidSpace, ...[...macs].sort()].join("\n"))
|
|
151
|
+
.digest("hex")
|
|
152
|
+
.slice(0, 32);
|
|
153
|
+
}
|
|
154
|
+
const THIS_HOST = { host: hostname(), machine: machineId(), alive: processAlive };
|
|
155
|
+
/** Parse a lock body; null when it is not one this code wrote. */
|
|
156
|
+
export function parseLockBody(text) {
|
|
157
|
+
let raw;
|
|
158
|
+
try {
|
|
159
|
+
raw = JSON.parse(text);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const parsed = lockBodySchema.safeParse(raw);
|
|
165
|
+
return parsed.success ? parsed.data : null;
|
|
166
|
+
}
|
|
167
|
+
const NOT_FOUND = /NOT_FOUND|not found|could not be found|does not exist/i;
|
|
168
|
+
const executionStatusSchema = z.object({
|
|
169
|
+
status: z
|
|
170
|
+
.object({
|
|
171
|
+
completionTime: z.string().optional(),
|
|
172
|
+
conditions: z
|
|
173
|
+
.array(z.object({
|
|
174
|
+
type: z.string(),
|
|
175
|
+
status: z.string(),
|
|
176
|
+
reason: z.string().optional(),
|
|
177
|
+
}))
|
|
178
|
+
.optional(),
|
|
179
|
+
})
|
|
180
|
+
.optional(),
|
|
181
|
+
});
|
|
182
|
+
/**
|
|
183
|
+
* Read an execution's state from `gcloud run jobs executions describe
|
|
184
|
+
* --format=json`. An execution has finished once Cloud Run stamped its
|
|
185
|
+
* completion time or decided its `Completed` condition (True: succeeded;
|
|
186
|
+
* False: failed or cancelled). Anything else is still running — including
|
|
187
|
+
* an execution Cloud Run has not started yet.
|
|
188
|
+
*/
|
|
189
|
+
export function parseExecutionState(result) {
|
|
190
|
+
if (!result.ok) {
|
|
191
|
+
if (NOT_FOUND.test(result.stderr))
|
|
192
|
+
return { kind: "not-found" };
|
|
193
|
+
return {
|
|
194
|
+
kind: "unknown",
|
|
195
|
+
error: result.stderr.trim() || `gcloud exited ${result.exitCode}`,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
let raw;
|
|
199
|
+
try {
|
|
200
|
+
raw = JSON.parse(result.stdout);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return { kind: "unknown", error: "gcloud returned no JSON for the execution" };
|
|
204
|
+
}
|
|
205
|
+
const parsed = executionStatusSchema.safeParse(raw);
|
|
206
|
+
if (!parsed.success) {
|
|
207
|
+
return { kind: "unknown", error: "gcloud returned an execution without a readable status" };
|
|
208
|
+
}
|
|
209
|
+
const status = parsed.data.status;
|
|
210
|
+
const completed = status?.conditions?.find((c) => c.type === "Completed");
|
|
211
|
+
if (completed && (completed.status === "True" || completed.status === "False")) {
|
|
212
|
+
const how = completed.status === "True" ? "succeeded" : (completed.reason ?? "failed").toLowerCase();
|
|
213
|
+
return { kind: "finished", how };
|
|
214
|
+
}
|
|
215
|
+
if (status?.completionTime)
|
|
216
|
+
return { kind: "finished", how: "completed" };
|
|
217
|
+
return { kind: "running" };
|
|
218
|
+
}
|
|
219
|
+
/** `gcloud run jobs executions describe`, for {@link judgeHeldLock}. */
|
|
220
|
+
export function describeExecutionArgs(ref) {
|
|
221
|
+
return [
|
|
222
|
+
"run",
|
|
223
|
+
"jobs",
|
|
224
|
+
"executions",
|
|
225
|
+
"describe",
|
|
226
|
+
ref.name,
|
|
227
|
+
`--region=${ref.region}`,
|
|
228
|
+
`--project=${ref.projectId}`,
|
|
229
|
+
"--format=json",
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Decide whether the lock with body `text` may be broken.
|
|
234
|
+
*
|
|
235
|
+
* @param describe looks the holder's execution up in Cloud Run; called only
|
|
236
|
+
* when the body names one
|
|
237
|
+
* @param now the judging run's clock, compared against the lease
|
|
238
|
+
* @param here this host's name and pid check, for a process holder's lock
|
|
239
|
+
*/
|
|
240
|
+
export function judgeHeldLock(text, describe, now, here = THIS_HOST) {
|
|
241
|
+
const body = parseLockBody(text);
|
|
242
|
+
if (!body) {
|
|
243
|
+
return {
|
|
244
|
+
kind: "held",
|
|
245
|
+
why: `the lock's holder is not readable (${text.trim().slice(0, 200) || "empty"})`,
|
|
246
|
+
manualRemoval: true,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const who = holderText(body);
|
|
250
|
+
if (!body.execution)
|
|
251
|
+
return judgeProcessLock(body, who, now, here);
|
|
252
|
+
const leaseUntil = body.leaseUntil ? Date.parse(body.leaseUntil) : Number.NaN;
|
|
253
|
+
const state = describe(body.execution);
|
|
254
|
+
switch (state.kind) {
|
|
255
|
+
case "finished":
|
|
256
|
+
return {
|
|
257
|
+
kind: "break",
|
|
258
|
+
why: `${who} has ${state.how}, but its lock was left behind`,
|
|
259
|
+
};
|
|
260
|
+
case "running":
|
|
261
|
+
return { kind: "held", why: `${who} is still running`, manualRemoval: false };
|
|
262
|
+
case "not-found":
|
|
263
|
+
if (Number.isNaN(leaseUntil)) {
|
|
264
|
+
return {
|
|
265
|
+
kind: "held",
|
|
266
|
+
why: `${who} is unknown to Cloud Run and its lock carries no readable lease`,
|
|
267
|
+
manualRemoval: true,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
if (now.getTime() > leaseUntil) {
|
|
271
|
+
return {
|
|
272
|
+
kind: "break",
|
|
273
|
+
why: `${who} is unknown to Cloud Run and its lease ended at ${body.leaseUntil}`,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
kind: "held",
|
|
278
|
+
why: `${who} is unknown to Cloud Run, but its lease runs until ${body.leaseUntil}`,
|
|
279
|
+
manualRemoval: false,
|
|
280
|
+
};
|
|
281
|
+
case "unknown":
|
|
282
|
+
return {
|
|
283
|
+
kind: "unknown",
|
|
284
|
+
why: `could not check whether ${who} is still running: ${state.error}`,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* A process holder's lock (a CLI run): broken when its pid is dead on this
|
|
290
|
+
* very host, or once its lease — renewed while the holder runs — expired.
|
|
291
|
+
*/
|
|
292
|
+
function judgeProcessLock(body, who, now, here) {
|
|
293
|
+
if (body.pid !== undefined && sameMachine(body, here) && !here.alive(body.pid)) {
|
|
294
|
+
return { kind: "break", why: `${who} has ended (its process is gone on this machine)` };
|
|
295
|
+
}
|
|
296
|
+
if (body.leaseUntil === undefined) {
|
|
297
|
+
// Written before #815: no lease to wait out, and its host may be
|
|
298
|
+
// another machine — only a person may remove it.
|
|
299
|
+
return { kind: "held", why: `held by ${who}`, manualRemoval: true };
|
|
300
|
+
}
|
|
301
|
+
const leaseUntil = Date.parse(body.leaseUntil);
|
|
302
|
+
if (Number.isNaN(leaseUntil)) {
|
|
303
|
+
return {
|
|
304
|
+
kind: "held",
|
|
305
|
+
why: `held by ${who}, whose lock carries no readable lease`,
|
|
306
|
+
manualRemoval: true,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
if (now.getTime() > leaseUntil) {
|
|
310
|
+
return {
|
|
311
|
+
kind: "break",
|
|
312
|
+
why: `${who} stopped renewing its lock; its lease ended at ${body.leaseUntil}`,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
kind: "held",
|
|
317
|
+
why: `held by ${who}; its lease runs until ${body.leaseUntil} unless renewed`,
|
|
318
|
+
manualRemoval: false,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Whether the lock was taken where `here` can check its pid. A lock naming
|
|
323
|
+
* a machine id needs this run's to match; one naming none (Cloud Run)
|
|
324
|
+
* never matches; a lock from before machine ids compares host names.
|
|
325
|
+
*/
|
|
326
|
+
function sameMachine(body, here) {
|
|
327
|
+
if (body.host !== here.host)
|
|
328
|
+
return false;
|
|
329
|
+
// A judge in Cloud Run shares its host name with every other container.
|
|
330
|
+
if (here.machine === null)
|
|
331
|
+
return false;
|
|
332
|
+
if (body.machine === undefined)
|
|
333
|
+
return true;
|
|
334
|
+
return body.machine !== null && here.machine != null && body.machine === here.machine;
|
|
335
|
+
}
|
|
336
|
+
/** "caelo upgrader job (run X, started T)" — for messages. */
|
|
337
|
+
function holderText(body) {
|
|
338
|
+
const parts = [];
|
|
339
|
+
if (body.execution)
|
|
340
|
+
parts.push(`run ${body.execution.name}`);
|
|
341
|
+
else if (body.host)
|
|
342
|
+
parts.push(`on ${body.host}${body.pid ? `, pid ${body.pid}` : ""}`);
|
|
343
|
+
if (body.startedAt)
|
|
344
|
+
parts.push(`started ${body.startedAt}`);
|
|
345
|
+
return parts.length > 0 ? `${body.purpose} (${parts.join(", ")})` : body.purpose;
|
|
346
|
+
}
|
|
347
|
+
//# sourceMappingURL=state-lock-lease.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-lock-lease.js","sourceRoot":"","sources":["../src/state-lock-lease.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgCxB,oEAAoE;AACpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,MAAM,CAAC;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAG,MAAM,CAAC;AAEx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SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;AACnF,CAAC"}
|
package/dist/state-store.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type GcloudResult } from "./gcloud.js";
|
|
2
|
+
import { type ExecutionLockHolder, type LocalHost } from "./state-lock-lease.js";
|
|
2
3
|
/** The two documents a store holds. */
|
|
3
4
|
export type StateFile = "install.json" | "progress.json";
|
|
4
5
|
/** Reads and writes an install's metadata documents. */
|
|
@@ -62,29 +63,85 @@ export declare class StateLockHeldError extends Error {
|
|
|
62
63
|
}
|
|
63
64
|
/** `gs://<bucket>/install/state.lock` — see {@link acquireBucketStateLock}. */
|
|
64
65
|
export declare function bucketStateLockUrl(bucket: string): string;
|
|
66
|
+
/** How a bucket lock is taken: who holds it, and the clock to judge leases by. */
|
|
67
|
+
export interface BucketLockOptions {
|
|
68
|
+
/**
|
|
69
|
+
* The Cloud Run execution taking the lock (#815): the lock's lease is the
|
|
70
|
+
* execution's task timeout, and a later run may break it once Cloud Run
|
|
71
|
+
* says this execution has finished. Without it the holder is this
|
|
72
|
+
* process (a CLI run): the lock names host + pid, carries a lease of
|
|
73
|
+
* {@link PROCESS_LEASE_MS} and is renewed by a heartbeat until released.
|
|
74
|
+
*/
|
|
75
|
+
readonly holder?: ExecutionLockHolder;
|
|
76
|
+
/** Told when a dead holder's lock was broken, with why. */
|
|
77
|
+
readonly onBreak?: (message: string) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Told when the heartbeat found the lock no longer this run's (another
|
|
80
|
+
* run broke it after the lease ran out, e.g. while this machine slept).
|
|
81
|
+
*/
|
|
82
|
+
readonly onLost?: (message: string) => void;
|
|
83
|
+
readonly now?: () => Date;
|
|
84
|
+
/** Starts the heartbeat; returns its stop. Defaults to an unref'd setInterval. */
|
|
85
|
+
readonly schedule?: (tick: () => void, everyMs: number) => () => void;
|
|
86
|
+
/** This host and its pid check (state-lock-lease.ts LocalHost); tests pass a fake. */
|
|
87
|
+
readonly here?: LocalHost;
|
|
88
|
+
}
|
|
65
89
|
/**
|
|
66
90
|
* The install's state lock in its ops bucket, created only if absent
|
|
67
91
|
* (`--if-generation-match=0`). Held by every writer of a bucket-backed
|
|
68
|
-
* install's state — an installer run's `pulumi up`, `state migrate
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* automatically.
|
|
92
|
+
* install's state — an installer run's `pulumi up`, `state migrate`, the
|
|
93
|
+
* CLI `upgrade`, the upgrader job — so none writes a backend another is
|
|
94
|
+
* switching away from.
|
|
72
95
|
*
|
|
73
|
-
*
|
|
96
|
+
* A lock that is held is judged (state-lock-lease.ts): one whose Cloud Run
|
|
97
|
+
* execution has finished, whose execution is gone after its lease, whose
|
|
98
|
+
* CLI process is gone on this host, or whose CLI lease ran out unrenewed,
|
|
99
|
+
* is broken with a generation-matched delete and taken once more. The
|
|
100
|
+
* generation is read BEFORE the body, so the delete can only remove the
|
|
101
|
+
* lock that was judged: if another run replaced it in between, the
|
|
102
|
+
* delete's precondition fails and nothing is removed. Two runs breaking the
|
|
103
|
+
* same dead lock cannot both win either — the slower one's create fails
|
|
104
|
+
* its own precondition and reports the lock as held.
|
|
105
|
+
*
|
|
106
|
+
* A CLI holder renews its lease every third of {@link PROCESS_LEASE_MS}
|
|
107
|
+
* with a generation-matched rewrite, so a run that is alive keeps its lock
|
|
108
|
+
* however long it takes, and a killed one loses it within one lease.
|
|
109
|
+
*
|
|
110
|
+
* @returns the release function; it stops the heartbeat and deletes only
|
|
111
|
+
* this lock's generation
|
|
112
|
+
* @throws StateLockHeldError when another run holds the lock
|
|
113
|
+
* @throws Error when the lock or its holder cannot be read (no access)
|
|
74
114
|
*/
|
|
75
|
-
export declare function acquireBucketStateLock(bucket: string, purpose: string, run?: SyncGcloud): () => void;
|
|
115
|
+
export declare function acquireBucketStateLock(bucket: string, purpose: string, run?: SyncGcloud, opts?: BucketLockOptions): () => void;
|
|
76
116
|
/**
|
|
77
117
|
* The same lock for an install whose state is on this machine:
|
|
78
|
-
* `~/.caelo-<id>/state.lock`, created exclusively.
|
|
118
|
+
* `~/.caelo-<id>/state.lock`, created exclusively. A lock left by a
|
|
119
|
+
* process that is gone on this machine is taken over (#815).
|
|
79
120
|
*
|
|
121
|
+
* @param here this host and its pid check; tests pass a fake
|
|
80
122
|
* @returns the release function
|
|
81
123
|
*/
|
|
82
|
-
export declare function acquireLocalStateLock(root: string, purpose: string): () => void;
|
|
124
|
+
export declare function acquireLocalStateLock(root: string, purpose: string, here?: LocalHost): () => void;
|
|
83
125
|
/** The state lock for whichever backend `bucket` (gcs) or `root` (local) names. */
|
|
84
126
|
export declare function acquireStateLock(backend: {
|
|
85
127
|
readonly kind: "local";
|
|
86
128
|
} | {
|
|
87
129
|
readonly kind: "gcs";
|
|
88
130
|
readonly bucket: string;
|
|
89
|
-
}, root: string, purpose: string, run?: SyncGcloud): () => void;
|
|
131
|
+
}, root: string, purpose: string, run?: SyncGcloud, opts?: BucketLockOptions): () => void;
|
|
132
|
+
/** The part of `process` {@link releaseOnSignal} needs; tests pass a fake. */
|
|
133
|
+
export interface SignalTarget {
|
|
134
|
+
once(signal: "SIGINT" | "SIGTERM", listener: () => void): unknown;
|
|
135
|
+
removeListener(signal: "SIGINT" | "SIGTERM", listener: () => void): unknown;
|
|
136
|
+
exit(code: number): never;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Give the state lock back when the CLI is stopped (Ctrl-C, a closed Cloud
|
|
140
|
+
* Shell tab's SIGTERM), then exit with the signal's conventional code
|
|
141
|
+
* (#815). Without this a stopped run leaves its lock until its lease ends.
|
|
142
|
+
*
|
|
143
|
+
* @param report told what happened to the lock
|
|
144
|
+
* @returns removes the handlers; call it once the run released the lock itself
|
|
145
|
+
*/
|
|
146
|
+
export declare function releaseOnSignal(release: () => void, report: (message: string) => void, proc?: SignalTarget): () => void;
|
|
90
147
|
//# sourceMappingURL=state-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-store.d.ts","sourceRoot":"","sources":["../src/state-store.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"state-store.d.ts","sourceRoot":"","sources":["../src/state-store.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAE3D,OAAO,EAEL,KAAK,mBAAmB,EAExB,KAAK,SAAS,EAOf,MAAM,uBAAuB,CAAC;AAE/B,uCAAuC;AACvC,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,eAAe,CAAC;AAEzD,wDAAwD;AACxD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,CAAC;IAC/B,2DAA2D;IAC3D,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAAC;IACrC,qDAAqD;IACrD,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9C;AAED,mFAAmF;AACnF,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,YAAY,CAAC;AAE1E,mEAAmE;AACnE,eAAO,MAAM,cAAc,EAAE,UAc5B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAIxE;AAcD,wDAAwD;AACxD,qBAAa,eAAgB,YAAW,UAAU;IAEpC,OAAO,CAAC,Q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