@catamorphic/work-server 0.1.0-alpha.42 → 0.1.0-alpha.44
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 +4 -1
- package/dist/agents.d.ts.map +1 -1
- package/dist/{chunk-kcck20aw.js → chunk-ynxz0am9.js} +80 -9
- package/dist/chunk-ynxz0am9.js.map +11 -0
- package/dist/cluster.d.ts +19 -1
- package/dist/cluster.d.ts.map +1 -1
- package/dist/execution-config.d.ts +2 -1
- package/dist/execution-config.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +962 -268
- package/dist/index.js.map +21 -19
- package/dist/machines/contract.d.ts +138 -14
- package/dist/machines/contract.d.ts.map +1 -1
- package/dist/machines/sequencer.d.ts +33 -6
- package/dist/machines/sequencer.d.ts.map +1 -1
- package/dist/machines/simulation.d.ts +64 -0
- package/dist/machines/simulation.d.ts.map +1 -1
- package/dist/machines/work-machines.d.ts +40 -2
- package/dist/machines/work-machines.d.ts.map +1 -1
- package/dist/server.d.ts +11 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +208 -17
- package/dist/testing.js.map +4 -4
- package/dist/workers/cache-archive-routes.d.ts +24 -0
- package/dist/workers/cache-archive-routes.d.ts.map +1 -0
- package/dist/workers/disk-care.d.ts +36 -1
- package/dist/workers/disk-care.d.ts.map +1 -1
- package/dist/workers/harness-sign-ins.d.ts +32 -1
- package/dist/workers/harness-sign-ins.d.ts.map +1 -1
- package/dist/workers/machine-store.d.ts +37 -0
- package/dist/workers/machine-store.d.ts.map +1 -1
- package/dist/workers/member-machine-routes.d.ts +3 -0
- package/dist/workers/member-machine-routes.d.ts.map +1 -1
- package/dist/workers/member-machines.d.ts +52 -5
- package/dist/workers/member-machines.d.ts.map +1 -1
- package/dist/workers/placement.d.ts +10 -0
- package/dist/workers/placement.d.ts.map +1 -1
- package/dist/workers/sign-in-store.d.ts +67 -0
- package/dist/workers/sign-in-store.d.ts.map +1 -0
- package/dist/workers/sign-ins.d.ts +4 -6
- package/dist/workers/sign-ins.d.ts.map +1 -1
- package/dist/workers/worker-protocol.d.ts +9 -1
- package/dist/workers/worker-protocol.d.ts.map +1 -1
- package/dist/workers/worker-registry.d.ts +20 -6
- package/dist/workers/worker-registry.d.ts.map +1 -1
- package/dist/workers/worker-runtime.d.ts.map +1 -1
- package/package.json +18 -19
- package/src/agents.ts +5 -0
- package/src/cluster.ts +62 -7
- package/src/execution-config.ts +2 -1
- package/src/index.ts +7 -0
- package/src/machines/contract-kit.ts +1 -1
- package/src/machines/contract.ts +191 -19
- package/src/machines/sequencer.ts +106 -11
- package/src/machines/simulation.ts +370 -20
- package/src/machines/work-machines.ts +71 -3
- package/src/server.ts +120 -29
- package/src/testing.ts +1 -0
- package/src/workers/cache-archive-routes.ts +125 -0
- package/src/workers/disk-care.ts +157 -6
- package/src/workers/harness-sign-ins.ts +207 -22
- package/src/workers/machine-store.ts +341 -58
- package/src/workers/member-machine-routes.ts +58 -3
- package/src/workers/member-machines.ts +168 -14
- package/src/workers/placement.ts +7 -0
- package/src/workers/sign-in-store.ts +241 -0
- package/src/workers/sign-ins.ts +9 -33
- package/src/workers/worker-protocol.ts +9 -1
- package/src/workers/worker-registry.ts +47 -6
- package/src/workers/worker-runtime.ts +9 -3
- package/dist/chunk-kcck20aw.js.map +0 -11
package/dist/testing.d.ts
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* `SimulatedWork` is that simulation, for a host's own scenarios.
|
|
5
5
|
*/
|
|
6
6
|
export { type ContractFacts, checkMachineProvisioner, checkMachinesHook, type MachineProvisioner, MachinesContractError, MemoryCloud, type MemoryCloudMachine, machinesHook, type PlatformProbe, } from "./machines/contract-kit.js";
|
|
7
|
-
export { quietSummary, type SimulatedCall, SimulatedWork, type SimulatedWorkOptions, } from "./machines/simulation.js";
|
|
7
|
+
export { quietSummary, type SimulatedCall, type SimulatedStart, SimulatedWork, type SimulatedWorkOptions, } from "./machines/simulation.js";
|
|
8
8
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,KAAK,aAAa,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,KAAK,kBAAkB,EACvB,qBAAqB,EACrB,WAAW,EACX,KAAK,kBAAkB,EACvB,YAAY,EACZ,KAAK,aAAa,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,oBAAoB,GAC1B,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,KAAK,aAAa,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,KAAK,kBAAkB,EACvB,qBAAqB,EACrB,WAAW,EACX,KAAK,kBAAkB,EACvB,YAAY,EACZ,KAAK,aAAa,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,aAAa,EACb,KAAK,oBAAoB,GAC1B,MAAM,0BAA0B,CAAC"}
|
package/dist/testing.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_LOST_AFTER_MINUTES2,
|
|
3
3
|
MachinePlanSchema,
|
|
4
|
+
SIGN_IN_WAIT_MINUTES,
|
|
5
|
+
preparedFor2,
|
|
4
6
|
normalizePrincipals,
|
|
5
7
|
machineStateOf,
|
|
6
8
|
lostAfterMsOf,
|
|
7
9
|
runMachinePass,
|
|
8
10
|
machineTakes,
|
|
9
11
|
canonical
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ynxz0am9.js";
|
|
11
13
|
|
|
12
14
|
// src/machines/contract-kit.ts
|
|
13
15
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -24,6 +26,7 @@ class SimulatedWork {
|
|
|
24
26
|
machines = new Map;
|
|
25
27
|
waitingWork = [];
|
|
26
28
|
waitingFor = new Map;
|
|
29
|
+
starts = new Map;
|
|
27
30
|
workCount = 0;
|
|
28
31
|
generations = 0;
|
|
29
32
|
neverConnect = new Set;
|
|
@@ -50,10 +53,13 @@ class SimulatedWork {
|
|
|
50
53
|
}
|
|
51
54
|
placedOn(workId) {
|
|
52
55
|
for (const machine of this.machines.values())
|
|
53
|
-
if (machine.holding.some((
|
|
56
|
+
if (machine.holding.some((held) => held.work.id === workId))
|
|
54
57
|
return machine.name;
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
60
|
+
startOf(workId) {
|
|
61
|
+
return this.starts.get(workId);
|
|
62
|
+
}
|
|
57
63
|
addWork(work) {
|
|
58
64
|
this.workCount += 1;
|
|
59
65
|
const added = {
|
|
@@ -66,6 +72,7 @@ class SimulatedWork {
|
|
|
66
72
|
requirements: { resources: {}, capabilities: [] },
|
|
67
73
|
reason: "unavailable",
|
|
68
74
|
waitingSince: this.now,
|
|
75
|
+
machine: null,
|
|
69
76
|
...work
|
|
70
77
|
};
|
|
71
78
|
this.waitingWork.push(added);
|
|
@@ -76,15 +83,58 @@ class SimulatedWork {
|
|
|
76
83
|
this.waitingWork = this.waitingWork.filter((work) => work.id !== workId);
|
|
77
84
|
for (const machine of this.machines.values()) {
|
|
78
85
|
const before = machine.holding.length;
|
|
79
|
-
machine.holding = machine.holding.filter((
|
|
86
|
+
machine.holding = machine.holding.filter((held) => held.work.id !== workId);
|
|
80
87
|
if (machine.holding.length < before)
|
|
81
88
|
machine.lastReleasedAt = this.clock;
|
|
82
89
|
}
|
|
83
90
|
}
|
|
91
|
+
quietWork(workId) {
|
|
92
|
+
const held = this.heldWorkspace(workId);
|
|
93
|
+
if (held?.state !== "busy")
|
|
94
|
+
return;
|
|
95
|
+
held.state = "quiet";
|
|
96
|
+
held.quietAt = this.clock;
|
|
97
|
+
}
|
|
98
|
+
workAgain(workId) {
|
|
99
|
+
const machine = [...this.machines.values()].find((candidate) => candidate.holding.some((held) => held.work.id === workId));
|
|
100
|
+
const held = this.heldWorkspace(workId);
|
|
101
|
+
if (!machine || !held || held.state === "busy")
|
|
102
|
+
return;
|
|
103
|
+
if (held.state === "quiet" || this.serves(machine)) {
|
|
104
|
+
held.state = "busy";
|
|
105
|
+
held.quietAt = null;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (this.waitingWork.some((work) => work.id === workId))
|
|
109
|
+
return;
|
|
110
|
+
this.waitingWork.push({
|
|
111
|
+
...held.work,
|
|
112
|
+
reason: "unavailable",
|
|
113
|
+
machine: machine.name,
|
|
114
|
+
waitingSince: this.now
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
heldWorkspace(workId) {
|
|
118
|
+
for (const machine of this.machines.values()) {
|
|
119
|
+
const held = machine.holding.find((entry) => entry.work.id === workId);
|
|
120
|
+
if (held)
|
|
121
|
+
return held;
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
serves(machine) {
|
|
126
|
+
return machine.phase === "running" && this.live(machine) && machine.droppedAt === null && machine.reset === null;
|
|
127
|
+
}
|
|
128
|
+
forgetStopped(machine) {
|
|
129
|
+
machine.holding = machine.holding.filter((held) => held.state !== "stopped");
|
|
130
|
+
this.waitingWork = this.waitingWork.map((work) => work.machine === machine.name && work.kind !== "sign-in" ? { ...work, machine: null } : work);
|
|
131
|
+
}
|
|
84
132
|
enrollByHand(args) {
|
|
85
133
|
const machine = this.blank({
|
|
86
134
|
name: args.name,
|
|
87
135
|
managed: false,
|
|
136
|
+
spare: false,
|
|
137
|
+
project: null,
|
|
88
138
|
for: args.for === undefined ? null : normalizePrincipals(args.for),
|
|
89
139
|
labels: args.labels ?? {},
|
|
90
140
|
trusted: args.trusted ?? false,
|
|
@@ -113,6 +163,15 @@ class SimulatedWork {
|
|
|
113
163
|
setDisabled(name, disabled) {
|
|
114
164
|
this.require(name).disabledAt = disabled ? this.clock : null;
|
|
115
165
|
}
|
|
166
|
+
beginSignIn(args) {
|
|
167
|
+
return this.addWork({
|
|
168
|
+
kind: "sign-in",
|
|
169
|
+
machine: args.machine,
|
|
170
|
+
user: args.member,
|
|
171
|
+
project: args.project,
|
|
172
|
+
...args.environment ? { environment: args.environment } : {}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
116
175
|
loseNextCreateAnswer() {
|
|
117
176
|
this.answerLost = true;
|
|
118
177
|
}
|
|
@@ -149,7 +208,7 @@ class SimulatedWork {
|
|
|
149
208
|
return { quiet: false, passes };
|
|
150
209
|
}
|
|
151
210
|
transient() {
|
|
152
|
-
return [...this.machines.values()].some((machine) => machine.phase === "stopping" || machine.phase === "destroying" || machine.phase === "resuming" && machine.alive === false || machine.phase === "starting" && machine.connectsAt !== null && !this.neverConnect.has(machine.name));
|
|
211
|
+
return [...this.machines.values()].some((machine) => machine.phase === "stopping" || machine.phase === "destroying" || machine.phase === "resuming" && machine.alive === false || machine.phase === "starting" && machine.connectsAt !== null && !this.neverConnect.has(machine.name) || machine.connectedPending && this.live(machine) || this.live(machine) && machine.preparations.some((entry) => entry.status === "preparing"));
|
|
153
212
|
}
|
|
154
213
|
get bootMs() {
|
|
155
214
|
return (this.options.bootSeconds ?? 60) * 1000;
|
|
@@ -163,6 +222,8 @@ class SimulatedWork {
|
|
|
163
222
|
blank(args) {
|
|
164
223
|
return {
|
|
165
224
|
...args,
|
|
225
|
+
preparations: [],
|
|
226
|
+
connectedPending: false,
|
|
166
227
|
ref: null,
|
|
167
228
|
enrollment: null,
|
|
168
229
|
generation: 0,
|
|
@@ -206,26 +267,93 @@ class SimulatedWork {
|
|
|
206
267
|
machine.startAskedAt = null;
|
|
207
268
|
machine.alive = true;
|
|
208
269
|
machine.connectsAt = null;
|
|
270
|
+
machine.connectedPending = true;
|
|
209
271
|
this.emit(kind, machine);
|
|
210
272
|
}
|
|
211
273
|
if (this.live(machine))
|
|
212
274
|
machine.lastSeenAt = this.clock;
|
|
275
|
+
for (const preparation of machine.preparations)
|
|
276
|
+
if (preparation.status === "preparing" && preparation.readyAt !== null && preparation.readyAt <= this.clock && this.live(machine)) {
|
|
277
|
+
const error = this.options.failPreparation?.({
|
|
278
|
+
machine: machine.name,
|
|
279
|
+
project: preparation.project,
|
|
280
|
+
environment: preparation.environment
|
|
281
|
+
});
|
|
282
|
+
preparation.status = error === undefined ? "prepared" : "failed";
|
|
283
|
+
preparation.error = error ?? null;
|
|
284
|
+
preparation.since = this.clock;
|
|
285
|
+
preparation.readyAt = null;
|
|
286
|
+
}
|
|
213
287
|
}
|
|
214
288
|
this.place();
|
|
215
289
|
}
|
|
216
290
|
place() {
|
|
217
291
|
const capacity = this.options.workspacesPerMachine ?? 4;
|
|
218
292
|
const isolation = this.options.isolation ?? "sandbox";
|
|
293
|
+
this.waitingWork = this.waitingWork.filter((work) => work.kind !== "sign-in" || this.clock - Date.parse(work.waitingSince) < SIGN_IN_WAIT_MINUTES * 60000);
|
|
219
294
|
this.waitingWork = this.waitingWork.filter((work) => {
|
|
220
|
-
|
|
295
|
+
if (work.kind === "sign-in") {
|
|
296
|
+
const machine = work.machine ? this.machines.get(work.machine) : null;
|
|
297
|
+
if (!machine || !this.serves(machine) || !machineTakes(machine, work))
|
|
298
|
+
return true;
|
|
299
|
+
this.starts.set(work.id, {
|
|
300
|
+
machine: machine.name,
|
|
301
|
+
at: this.now,
|
|
302
|
+
imageBuilt: false,
|
|
303
|
+
cachesFilled: false
|
|
304
|
+
});
|
|
305
|
+
this.waitingFor.delete(work.id);
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
if (work.machine !== null) {
|
|
309
|
+
const keeper = this.machines.get(work.machine);
|
|
310
|
+
const held = keeper?.holding.find((entry) => entry.work.id === work.id);
|
|
311
|
+
if (!keeper || !held)
|
|
312
|
+
return true;
|
|
313
|
+
if (!this.serves(keeper))
|
|
314
|
+
return true;
|
|
315
|
+
held.state = "busy";
|
|
316
|
+
held.quietAt = null;
|
|
317
|
+
this.waitingFor.delete(work.id);
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
const takers = [...this.machines.values()].filter((machine) => machine.phase === "running" && this.live(machine) && machine.droppedAt === null && machine.reset === null && machine.holding.length < capacity && (machine.trusted || isolation === "sandbox" || machine.for !== null && machine.for.length === 1) && machineTakes(machine, work)).sort((left, right) => (left.for?.length ?? Number.POSITIVE_INFINITY) - (right.for?.length ?? Number.POSITIVE_INFINITY) || Number(this.warm(right, work)) - Number(this.warm(left, work)));
|
|
221
321
|
const taker = takers[0];
|
|
222
322
|
if (!taker)
|
|
223
323
|
return true;
|
|
224
|
-
|
|
324
|
+
const warm = this.warm(taker, work);
|
|
325
|
+
taker.holding.push({ work, state: "busy", quietAt: null });
|
|
326
|
+
if (taker.spare && work.key !== null && work.kind !== "fill") {
|
|
327
|
+
taker.for = [{ project: work.project, key: work.key }];
|
|
328
|
+
taker.spare = false;
|
|
329
|
+
}
|
|
330
|
+
this.starts.set(work.id, {
|
|
331
|
+
machine: taker.name,
|
|
332
|
+
at: this.now,
|
|
333
|
+
imageBuilt: !warm,
|
|
334
|
+
cachesFilled: !warm
|
|
335
|
+
});
|
|
225
336
|
this.waitingFor.delete(work.id);
|
|
226
337
|
return false;
|
|
227
338
|
});
|
|
228
339
|
}
|
|
340
|
+
warm(machine, work) {
|
|
341
|
+
return preparedFor2({
|
|
342
|
+
machine: { preparations: this.preparationsOf(machine) },
|
|
343
|
+
project: work.project,
|
|
344
|
+
environment: work.environment
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
preparationsOf(machine) {
|
|
348
|
+
return machine.preparations.map((preparation) => ({
|
|
349
|
+
project: preparation.project,
|
|
350
|
+
environment: preparation.environment,
|
|
351
|
+
status: preparation.status,
|
|
352
|
+
commit: preparation.commit,
|
|
353
|
+
error: preparation.error,
|
|
354
|
+
since: iso(preparation.since)
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
229
357
|
emit(kind, machine) {
|
|
230
358
|
const event = {
|
|
231
359
|
kind,
|
|
@@ -236,6 +364,7 @@ class SimulatedWork {
|
|
|
236
364
|
managed: machine.managed,
|
|
237
365
|
labels: machine.labels,
|
|
238
366
|
for: machine.for,
|
|
367
|
+
project: machine.project,
|
|
239
368
|
options: machine.options,
|
|
240
369
|
reason: machine.reason
|
|
241
370
|
}
|
|
@@ -261,6 +390,7 @@ class SimulatedWork {
|
|
|
261
390
|
});
|
|
262
391
|
const since = state === "unreachable" || state === "lost" ? machine.phase === "resuming" ? machine.startAskedAt ?? seen : seen : state === "disabled" ? machine.disabledAt ?? machine.phaseSince : state === "draining" ? machine.droppedAt ?? machine.phaseSince : machine.phaseSince;
|
|
263
392
|
const connected = machine.phase !== "starting";
|
|
393
|
+
const live = machine.holding.filter((held) => held.state !== "stopped");
|
|
264
394
|
const facts = {
|
|
265
395
|
name: machine.name,
|
|
266
396
|
ref: machine.ref,
|
|
@@ -269,14 +399,18 @@ class SimulatedWork {
|
|
|
269
399
|
since: iso(since),
|
|
270
400
|
labels: machine.labels,
|
|
271
401
|
for: machine.for,
|
|
402
|
+
spare: machine.spare,
|
|
403
|
+
project: machine.project,
|
|
404
|
+
preparations: this.preparationsOf(machine),
|
|
272
405
|
trusted: machine.trusted,
|
|
273
406
|
options: machine.options,
|
|
274
407
|
reason: machine.reason,
|
|
275
408
|
holding: {
|
|
276
|
-
workspaces:
|
|
277
|
-
|
|
409
|
+
workspaces: live.length,
|
|
410
|
+
stopped: machine.holding.length - live.length,
|
|
411
|
+
for: normalizePrincipals(live.map(({ work }) => work.user !== null ? { user: work.user } : work.key !== null ? { project: work.project, key: work.key } : { project: work.project }))
|
|
278
412
|
},
|
|
279
|
-
|
|
413
|
+
quietSince: (state === "serving" || state === "draining") && live.every((held) => held.state === "quiet") ? iso(Math.max(machine.phaseSince, machine.lastReleasedAt ?? 0, ...live.map((held) => held.quietAt ?? 0))) : null,
|
|
280
414
|
lastSeenAt: machine.lastSeenAt === null ? null : iso(machine.lastSeenAt),
|
|
281
415
|
capacity: connected ? { workspaces: capacity } : null,
|
|
282
416
|
usage: connected ? {
|
|
@@ -306,7 +440,8 @@ class SimulatedWork {
|
|
|
306
440
|
startAsked: machine.startAskedAt !== null,
|
|
307
441
|
destroyRequestedAt: machine.destroyRequestedAt === null ? null : iso(machine.destroyRequestedAt),
|
|
308
442
|
lostAfterMinutes: machine.lostAfterMinutes,
|
|
309
|
-
revoked: machine.revoked
|
|
443
|
+
revoked: machine.revoked,
|
|
444
|
+
connectedPending: machine.connectedPending
|
|
310
445
|
};
|
|
311
446
|
});
|
|
312
447
|
}
|
|
@@ -332,8 +467,19 @@ class SimulatedWork {
|
|
|
332
467
|
const stop = hook.stop?.bind(hook);
|
|
333
468
|
const start = hook.start?.bind(hook);
|
|
334
469
|
const describe = hook.describe?.bind(hook);
|
|
470
|
+
const onConnected = hook.onConnected?.bind(hook);
|
|
335
471
|
return {
|
|
336
472
|
plan: (facts) => hook.plan(facts),
|
|
473
|
+
...onConnected ? {
|
|
474
|
+
onConnected: (args) => record({
|
|
475
|
+
verb: "onConnected",
|
|
476
|
+
name: args.machine.name,
|
|
477
|
+
ref: args.machine.ref,
|
|
478
|
+
idempotencyKey: null
|
|
479
|
+
}, async () => {
|
|
480
|
+
await onConnected(args);
|
|
481
|
+
})
|
|
482
|
+
} : {},
|
|
337
483
|
create: async (request) => {
|
|
338
484
|
const entry = {
|
|
339
485
|
verb: "create",
|
|
@@ -384,8 +530,14 @@ class SimulatedWork {
|
|
|
384
530
|
machine.revoked = true;
|
|
385
531
|
machine.alive = false;
|
|
386
532
|
machine.connectsAt = null;
|
|
387
|
-
|
|
388
|
-
|
|
533
|
+
this.forgetStopped(machine);
|
|
534
|
+
for (const { work, state } of machine.holding)
|
|
535
|
+
if (state === "busy")
|
|
536
|
+
this.waitingWork.push({
|
|
537
|
+
...work,
|
|
538
|
+
machine: null,
|
|
539
|
+
waitingSince: this.now
|
|
540
|
+
});
|
|
389
541
|
machine.holding = [];
|
|
390
542
|
};
|
|
391
543
|
return {
|
|
@@ -401,6 +553,8 @@ class SimulatedWork {
|
|
|
401
553
|
name: planned.name,
|
|
402
554
|
managed: true,
|
|
403
555
|
for: planned.for,
|
|
556
|
+
spare: planned.spare,
|
|
557
|
+
project: planned.project,
|
|
404
558
|
labels: planned.labels,
|
|
405
559
|
trusted: planned.trusted,
|
|
406
560
|
options: planned.options,
|
|
@@ -439,6 +593,34 @@ class SimulatedWork {
|
|
|
439
593
|
machine.trusted = settings.trusted;
|
|
440
594
|
machine.reason = settings.reason;
|
|
441
595
|
machine.lostAfterMinutes = settings.lostAfterMinutes;
|
|
596
|
+
machine.spare = settings.spare;
|
|
597
|
+
machine.project = settings.project;
|
|
598
|
+
}),
|
|
599
|
+
prepare: async ({ name, project, environment, commit }) => {
|
|
600
|
+
const machine = this.require(name);
|
|
601
|
+
const existing = machine.preparations.find((entry) => entry.project === project && entry.environment === environment);
|
|
602
|
+
if (!existing || existing.status === "failed") {
|
|
603
|
+
const started = {
|
|
604
|
+
project,
|
|
605
|
+
environment,
|
|
606
|
+
status: "preparing",
|
|
607
|
+
commit: commit ?? null,
|
|
608
|
+
error: null,
|
|
609
|
+
since: this.clock,
|
|
610
|
+
readyAt: this.clock + (this.options.prepareSeconds ?? 600) * 1000
|
|
611
|
+
};
|
|
612
|
+
machine.preparations = [
|
|
613
|
+
...machine.preparations.filter((entry) => entry !== existing),
|
|
614
|
+
started
|
|
615
|
+
];
|
|
616
|
+
}
|
|
617
|
+
const preparation = this.preparationsOf(machine).find((entry) => entry.project === project && entry.environment === environment);
|
|
618
|
+
if (!preparation)
|
|
619
|
+
throw new Error("The preparation was not recorded");
|
|
620
|
+
return preparation;
|
|
621
|
+
},
|
|
622
|
+
heardConnected: async ({ name }) => set(name, (machine) => {
|
|
623
|
+
machine.connectedPending = false;
|
|
442
624
|
}),
|
|
443
625
|
setFor: async ({ name, for: principals }) => set(name, (machine) => {
|
|
444
626
|
machine.for = principals;
|
|
@@ -451,11 +633,13 @@ class SimulatedWork {
|
|
|
451
633
|
const machine = this.require(name);
|
|
452
634
|
if (!this.live(machine))
|
|
453
635
|
return "offline";
|
|
454
|
-
if (machine.holding.
|
|
636
|
+
if (machine.holding.some((held) => held.state !== "stopped"))
|
|
455
637
|
return "busy";
|
|
638
|
+
this.forgetStopped(machine);
|
|
456
639
|
machine.for = machine.reset?.for ?? machine.for;
|
|
457
640
|
machine.reset = null;
|
|
458
641
|
machine.resets += 1;
|
|
642
|
+
machine.preparations = [];
|
|
459
643
|
return "done";
|
|
460
644
|
},
|
|
461
645
|
drop: async ({ name }) => set(name, (machine) => {
|
|
@@ -466,7 +650,7 @@ class SimulatedWork {
|
|
|
466
650
|
}),
|
|
467
651
|
retire: async ({ name }) => {
|
|
468
652
|
const machine = this.require(name);
|
|
469
|
-
if (machine.holding.
|
|
653
|
+
if (machine.holding.some((held) => held.state !== "stopped") && !machine.revoked)
|
|
470
654
|
return false;
|
|
471
655
|
condemn(machine);
|
|
472
656
|
return true;
|
|
@@ -483,8 +667,12 @@ class SimulatedWork {
|
|
|
483
667
|
},
|
|
484
668
|
beginStop: async ({ name }) => {
|
|
485
669
|
const machine = this.require(name);
|
|
486
|
-
if (machine.holding.
|
|
670
|
+
if (machine.holding.some((held) => held.state === "busy") || machine.phase !== "running")
|
|
487
671
|
return false;
|
|
672
|
+
for (const held of machine.holding) {
|
|
673
|
+
held.state = "stopped";
|
|
674
|
+
held.quietAt = null;
|
|
675
|
+
}
|
|
488
676
|
phase(machine, "stopping");
|
|
489
677
|
return true;
|
|
490
678
|
},
|
|
@@ -504,6 +692,9 @@ class SimulatedWork {
|
|
|
504
692
|
machine.connectsAt = this.clock + this.bootMs;
|
|
505
693
|
}),
|
|
506
694
|
forget: async ({ name }) => {
|
|
695
|
+
const machine = this.machines.get(name);
|
|
696
|
+
if (machine)
|
|
697
|
+
this.forgetStopped(machine);
|
|
507
698
|
this.machines.delete(name);
|
|
508
699
|
},
|
|
509
700
|
note: async ({ name, notice }) => set(name, (machine) => {
|
|
@@ -896,7 +1087,7 @@ async function checkMachinesHook(args) {
|
|
|
896
1087
|
if (after.length > 0)
|
|
897
1088
|
fail("plan does not flap", [
|
|
898
1089
|
`Nothing changed, yet within a simulated minute the plan had machines made or destroyed: ${recent(after)}.`,
|
|
899
|
-
"Keep a machine while the reason for it holds. If the plan drops machines that are
|
|
1090
|
+
"Keep a machine while the reason for it holds. If the plan drops or stops machines that are quiet, give them a quiet time of minutes, not seconds, and measure it from the machine's own quietSince."
|
|
900
1091
|
]);
|
|
901
1092
|
for (const [name, calls] of groupByName(creates(sim.calls))) {
|
|
902
1093
|
const keys = new Set(calls.map((call) => call.idempotencyKey));
|
|
@@ -1009,5 +1200,5 @@ export {
|
|
|
1009
1200
|
quietSummary
|
|
1010
1201
|
};
|
|
1011
1202
|
|
|
1012
|
-
//# debugId=
|
|
1203
|
+
//# debugId=FE004803F72FF1BF64756E2164756E21
|
|
1013
1204
|
//# sourceMappingURL=testing.js.map
|