@zgeoff/atc 3.3.0 → 3.3.1
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/package.json +1 -1
- package/src/verify-restored-fleet.ts +39 -3
package/package.json
CHANGED
|
@@ -28,7 +28,9 @@ const UNSIZED_READ_MS = 30_000;
|
|
|
28
28
|
* passes (`timeoutSeconds` when set, else the rows that are not exited times the restore boot cap, plus 30 s), and an exited row must be listed. A stored row that is not listed
|
|
29
29
|
* failed to restore, and a listed row that is still without a live terminal
|
|
30
30
|
* at the deadline failed to revive. The deadline counts from the call, and
|
|
31
|
-
* every request to the daemon is held to it
|
|
31
|
+
* every request to the daemon is held to it: the daemon must answer the first
|
|
32
|
+
* list before it, and when it overtakes a later list, the verdict comes from
|
|
33
|
+
* the last list the daemon answered.
|
|
32
34
|
*/
|
|
33
35
|
export async function verifyRestoredFleet(
|
|
34
36
|
client: Pick<DaemonClient, 'sendRequest'>,
|
|
@@ -54,9 +56,15 @@ export async function verifyRestoredFleet(
|
|
|
54
56
|
let found = await sendBounded(() => collectFailedRows(client, stored, restored), deadline);
|
|
55
57
|
|
|
56
58
|
while (found.pending && Date.now() < deadline) {
|
|
57
|
-
await Bun.sleep(250);
|
|
59
|
+
await Bun.sleep(Math.min(250, deadline - Date.now()));
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
const polled = await tryCollectFailedRows(client, stored, restored, deadline);
|
|
62
|
+
|
|
63
|
+
if (polled === null) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
found = polled;
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
return { total: stored.length, failed: found.failed };
|
|
@@ -109,6 +117,34 @@ async function tryRestore(
|
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Lists the rows again, or returns null when the deadline passes before the
|
|
122
|
+
* daemon answers, so the caller keeps the verdict of the last list it got.
|
|
123
|
+
*/
|
|
124
|
+
async function tryCollectFailedRows(
|
|
125
|
+
client: Pick<DaemonClient, 'sendRequest'>,
|
|
126
|
+
stored: readonly StoredRow[],
|
|
127
|
+
restored: boolean,
|
|
128
|
+
deadline: number,
|
|
129
|
+
): Promise<FailedRows | null> {
|
|
130
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
131
|
+
|
|
132
|
+
const expired = new Promise<null>((resolve) => {
|
|
133
|
+
timer = setTimeout(
|
|
134
|
+
() => {
|
|
135
|
+
resolve(null);
|
|
136
|
+
},
|
|
137
|
+
Math.max(0, deadline - Date.now()),
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
return await Promise.race([collectFailedRows(client, stored, restored), expired]);
|
|
143
|
+
} finally {
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
112
148
|
async function collectFailedRows(
|
|
113
149
|
client: Pick<DaemonClient, 'sendRequest'>,
|
|
114
150
|
stored: readonly StoredRow[],
|