deepline 0.3.509 → 0.3.510
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/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/monitors/org-monitor-limits.ts +7 -2
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/roll-execution-relay.ts +94 -43
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/roll-receipt-gateway.ts +111 -27
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/runtime-topology.ts +79 -6
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +80 -6
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-transient-retry.ts +571 -0
- package/dist/cli/auth-S2Z5YMU3.js +43 -0
- package/dist/cli/{auth-6IR2QH4N.mjs → auth-USS2W3UV.mjs} +5 -5
- package/dist/cli/{billing-WEWHH6ST.mjs → billing-JCUWM5XB.mjs} +7 -7
- package/dist/cli/{billing-SYBK3ZYU.js → billing-LQQHU443.js} +82 -82
- package/dist/cli/{chunk-7NMPGX3W.js → chunk-2JXEZAJF.js} +21 -21
- package/dist/cli/chunk-3LXU22UZ.js +77 -0
- package/dist/cli/{chunk-7KALZEDZ.js → chunk-4NJK6P5T.js} +4 -4
- package/dist/cli/{chunk-VTVZ7EUA.js → chunk-4ZIIS6KG.js} +9 -9
- package/dist/cli/{chunk-2U7Z4LFG.mjs → chunk-563HM4D2.mjs} +6 -6
- package/dist/cli/{chunk-T67NAGSD.mjs → chunk-5DU7RXDW.mjs} +4 -4
- package/dist/cli/{chunk-FQCIYGQY.mjs → chunk-5MYXW6M6.mjs} +2 -2
- package/dist/cli/{chunk-5Y3I5LEQ.js → chunk-5N2HFB3G.js} +16 -16
- package/dist/cli/{chunk-WPBTWRKG.js → chunk-63DHG7BM.js} +26 -26
- package/dist/cli/{chunk-GTAU4C44.js → chunk-6AL2VF3E.js} +14 -14
- package/dist/cli/{chunk-OOD5LGUS.mjs → chunk-7BF4R26M.mjs} +3 -3
- package/dist/cli/{chunk-6TBRWRJ2.js → chunk-7VQKU6MS.js} +7 -7
- package/dist/cli/{chunk-EEEWADSR.mjs → chunk-7VT7RMZ2.mjs} +2 -2
- package/dist/cli/{chunk-O527H5GY.js → chunk-ASBWPRBN.js} +16 -16
- package/dist/cli/{chunk-4DVANPBN.js → chunk-B2T7PBS6.js} +41 -41
- package/dist/cli/{chunk-UART6FGK.mjs → chunk-B2U3LVSO.mjs} +1 -1
- package/dist/cli/{chunk-S7JEF2MR.mjs → chunk-B6Q6BHSY.mjs} +2 -2
- package/dist/cli/{chunk-Z2LVZDO5.js → chunk-BPGFNVH2.js} +44 -44
- package/dist/cli/{chunk-FNLGMMJJ.mjs → chunk-CLV4T5FN.mjs} +2 -2
- package/dist/cli/{chunk-54YPOG5W.mjs → chunk-DEPBCRKG.mjs} +15 -4
- package/dist/cli/{chunk-6KBVQ76G.mjs → chunk-DMF56C6D.mjs} +2 -2
- package/dist/cli/{chunk-VZ773N7G.js → chunk-EEQ2QQOH.js} +21 -10
- package/dist/cli/{chunk-XEQH65DT.mjs → chunk-EJ57CA2L.mjs} +1 -1
- package/dist/cli/{chunk-CMSPA5VX.js → chunk-F6IXWFPF.js} +6 -6
- package/dist/cli/{chunk-VH522HUP.mjs → chunk-FFPLCSTZ.mjs} +10 -10
- package/dist/cli/{chunk-WJ6H2W3O.mjs → chunk-FND6GZZ4.mjs} +5 -5
- package/dist/cli/{chunk-Q7G6WORO.js → chunk-HC27PYJM.js} +2 -2
- package/dist/cli/{chunk-R2KNJMOY.mjs → chunk-HOKOJGQW.mjs} +1 -1
- package/dist/cli/{chunk-2ZJRCAHG.js → chunk-JNECQ5QF.js} +11 -11
- package/dist/cli/chunk-JVEU6MXD.mjs +77 -0
- package/dist/cli/{chunk-ZXGMWXZW.js → chunk-JY73USD7.js} +2 -2
- package/dist/cli/{chunk-IZW7IOD6.mjs → chunk-KXSOZYCS.mjs} +1 -1
- package/dist/cli/{chunk-AO63MXT6.js → chunk-LF3FF2B2.js} +1 -1
- package/dist/cli/{chunk-DGOSW42X.js → chunk-N7FV7OM3.js} +96 -96
- package/dist/cli/{chunk-K2RCVD7S.mjs → chunk-OEG6VCK4.mjs} +1 -1
- package/dist/cli/{chunk-3CZHC24N.mjs → chunk-PQ56GE55.mjs} +1 -1
- package/dist/cli/{chunk-XIBNY6H6.mjs → chunk-Q5EJO4TE.mjs} +5 -5
- package/dist/cli/{chunk-Q5UO2ENN.js → chunk-QRQBKLOM.js} +3 -3
- package/dist/cli/{chunk-WUKNKFB3.mjs → chunk-RHKFNEV2.mjs} +2 -2
- package/dist/cli/{chunk-E3HWUGDT.mjs → chunk-UV524JZ5.mjs} +1 -1
- package/dist/cli/{chunk-RSKAPLST.mjs → chunk-V6DLYRSO.mjs} +1 -1
- package/dist/cli/{chunk-HMAETS53.js → chunk-VPJSQMWQ.js} +3 -3
- package/dist/cli/{chunk-25MAOMVS.mjs → chunk-WAOLTP6R.mjs} +2 -2
- package/dist/cli/{chunk-Y4M5HPQV.mjs → chunk-WC5754QJ.mjs} +5 -5
- package/dist/cli/{chunk-AD45WJHN.js → chunk-XJZU7KO4.js} +5 -5
- package/dist/cli/{chunk-J5P4PDRT.js → chunk-XK3AJFYQ.js} +32 -10
- package/dist/cli/{chunk-726UDAV2.js → chunk-XL4FFVWL.js} +7 -7
- package/dist/cli/{chunk-JZJNA57M.js → chunk-XRLE2FPE.js} +6 -6
- package/dist/cli/{chunk-XPKBYMJH.js → chunk-YDALHHUC.js} +53 -53
- package/dist/cli/{chunk-SEQIB5WJ.mjs → chunk-YYUVOUEH.mjs} +5 -5
- package/dist/cli/{chunk-RA2NKHV5.js → chunk-ZCYV6MZH.js} +5 -5
- package/dist/cli/{chunk-YJM3NOME.mjs → chunk-ZRACZKEE.mjs} +32 -10
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-4LAJ2ZKG.mjs → csv-MTFVEDPU.mjs} +4 -4
- package/dist/cli/{csv-5KNONIAX.js → csv-UXFQZLZM.js} +13 -13
- package/dist/cli/{db-BEVCJI66.mjs → db-3WPUYCCI.mjs} +6 -6
- package/dist/cli/{db-5PEXOSN3.js → db-RGWT6B7K.js} +27 -27
- package/dist/cli/describe-LNCLA2LA.js +50 -0
- package/dist/cli/{describe-TDJIUSD6.mjs → describe-XJY5654F.mjs} +18 -18
- package/dist/cli/{executions-36GV3A27.js → executions-IWTALFNB.js} +8 -8
- package/dist/cli/{executions-KXCPU6YC.mjs → executions-PDE4V5YH.mjs} +6 -6
- package/dist/cli/{feedback-GEUUT4S7.mjs → feedback-BMOVTPC4.mjs} +11 -7
- package/dist/cli/{feedback-SPQABV33.js → feedback-I72P4XZS.js} +15 -11
- package/dist/cli/{git-AE36X2R6.mjs → git-QJG3EF4P.mjs} +5 -5
- package/dist/cli/git-QWH7SPGF.js +25 -0
- package/dist/cli/index.js +173 -156
- package/dist/cli/index.mjs +76 -59
- package/dist/cli/{legacy-noops-TKPHN7WT.js → legacy-noops-5P75CQC7.js} +9 -8
- package/dist/cli/{legacy-noops-LUEDAK7J.mjs → legacy-noops-MZ45GDMK.mjs} +6 -5
- package/dist/cli/{monitors-B2EAIGZI.js → monitors-5PHQZDZM.js} +100 -100
- package/dist/cli/{monitors-JHJZ5XG7.mjs → monitors-VIOBUG2X.mjs} +7 -7
- package/dist/cli/{org-PYCPXEAU.js → org-B5LDVP2P.js} +72 -72
- package/dist/cli/{org-GUICCEBZ.mjs → org-D5RTFJNY.mjs} +6 -6
- package/dist/cli/{pages-CV4TQNFY.js → pages-BUJYG3JL.js} +18 -18
- package/dist/cli/{pages-Y2XI36HY.mjs → pages-XWZL3YV2.mjs} +6 -6
- package/dist/cli/{play-VWCQNGZZ.mjs → play-OSXLGCLZ.mjs} +18 -18
- package/dist/cli/{play-MTVK66JK.js → play-SEC3EE7H.js} +317 -317
- package/dist/cli/{providers-ZOZTST3A.mjs → providers-ENSURIW6.mjs} +6 -6
- package/dist/cli/{providers-N72BUCXZ.js → providers-RQPUASLI.js} +9 -9
- package/dist/cli/{quickstart-DXIC3NHS.mjs → quickstart-HJTK6XWI.mjs} +4 -4
- package/dist/cli/{quickstart-FK53VZB3.js → quickstart-XDTU4MAT.js} +6 -6
- package/dist/cli/{run-NNAYDCEN.js → run-GX2SU5AT.js} +41 -41
- package/dist/cli/{run-IL2KI33N.mjs → run-ZMWSQAR2.mjs} +23 -23
- package/dist/cli/search-7WPABWYO.js +33 -0
- package/dist/cli/{search-7IPVMQCO.mjs → search-DZHZBHWT.mjs} +8 -8
- package/dist/cli/{search-output-YHTWLSDE.js → search-output-3JVZERNV.js} +6 -6
- package/dist/cli/{search-output-ZY2GE35S.mjs → search-output-MNHAR754.mjs} +4 -4
- package/dist/cli/{secrets-BGUMHDZ7.mjs → secrets-VALVNVXB.mjs} +6 -6
- package/dist/cli/{secrets-ZML76SH2.js → secrets-WO2LMDQ2.js} +15 -15
- package/dist/cli/sessions-2IA2DGWO.js +18 -0
- package/dist/cli/{sessions-F5XO6HZJ.mjs → sessions-EPYCH3AY.mjs} +6 -5
- package/dist/cli/{settings-TOX2P5M5.js → settings-OSF4O5HM.js} +109 -82
- package/dist/cli/{settings-73SMIICV.mjs → settings-W2ABZUD4.mjs} +39 -12
- package/dist/cli/{setup-DNFHFQ7N.js → setup-DCXNQG6R.js} +50 -50
- package/dist/cli/{setup-FDJZYBMS.mjs → setup-XI2ERSMQ.mjs} +10 -10
- package/dist/cli/skills-QMD2WARJ.js +37 -0
- package/dist/cli/{skills-6HJ2IAY6.mjs → skills-ZO4AH2YR.mjs} +8 -8
- package/dist/cli/tools-53E6GBQU.js +57 -0
- package/dist/cli/{tools-4FJIIE4R.mjs → tools-FTECXZYA.mjs} +17 -17
- package/dist/cli/update-PPPNR6J5.js +35 -0
- package/dist/cli/{update-UMRPPILV.mjs → update-WPFZO2JE.mjs} +10 -10
- package/dist/cli/{workflow-LSFOG5VU.mjs → workflow-7X75IP3D.mjs} +7 -7
- package/dist/cli/{workflow-SK3BUHB4.js → workflow-PKMU33LV.js} +17 -17
- package/dist/index.js +9 -9
- package/dist/index.mjs +6 -6
- package/dist/install-integrity.json +105 -102
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +2 -2
- package/dist/release.mjs +1 -1
- package/dist/server.js +5 -5
- package/dist/server.mjs +3 -3
- package/package.json +1 -1
- package/dist/cli/auth-SUTQ4SZQ.js +0 -43
- package/dist/cli/describe-ZB6G6DOV.js +0 -50
- package/dist/cli/git-UX7L6R32.js +0 -25
- package/dist/cli/search-OZHP5ZE2.js +0 -33
- package/dist/cli/sessions-WDINUUZ3.js +0 -17
- package/dist/cli/skills-NE7WN5PP.js +0 -37
- package/dist/cli/tools-ETX4MNNO.js +0 -57
- package/dist/cli/update-N2DMPSUH.js +0 -35
|
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
|
|
|
205
205
|
// getters keep their established compatibility behavior.
|
|
206
206
|
// 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
|
|
207
207
|
// 0.3.90 is the first deliberately versioned SDK release for API v3.
|
|
208
|
-
version: '0.3.
|
|
208
|
+
version: '0.3.510',
|
|
209
209
|
updateSummary: {
|
|
210
210
|
introducedIn: '0.3.90',
|
|
211
211
|
summary:
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* What an organization may watch.
|
|
3
3
|
*
|
|
4
4
|
* Monitors are priced and reasoned about in accounts, not in rows: an
|
|
5
|
-
*
|
|
6
|
-
* on each
|
|
5
|
+
* workspace can watch up to its plan's account limit and watch several signals
|
|
6
|
+
* on each account. A flat monitor ceiling could not express either half - it
|
|
7
7
|
* let one company consume the whole allowance, and it made "how many accounts
|
|
8
8
|
* can I watch" unanswerable without knowing how many signals each would use.
|
|
9
9
|
*
|
|
@@ -11,8 +11,13 @@
|
|
|
11
11
|
* product and is deliberately not a third number to reason about.
|
|
12
12
|
*/
|
|
13
13
|
import { ORG_LIMITS, OrgLimit } from '@deepline/billing/org-limits/registry';
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_PLAN_KEY,
|
|
16
|
+
PLAN_LIMITS,
|
|
17
|
+
} from '@deepline/billing/org-limits/plans';
|
|
14
18
|
|
|
15
19
|
export const DEFAULT_ORG_MONITOR_ENTITY_LIMIT =
|
|
20
|
+
PLAN_LIMITS[DEFAULT_PLAN_KEY][OrgLimit.MonitorWatchedEntities] ??
|
|
16
21
|
ORG_LIMITS[OrgLimit.MonitorWatchedEntities].defaultValue;
|
|
17
22
|
|
|
18
23
|
/** Signals one account may be watched with, e.g. jobs + funding + news. */
|
package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/roll-execution-relay.ts
CHANGED
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { spawnSync } from 'node:child_process';
|
|
13
13
|
import { FlyMachinesClient, requireFlyToken } from '../fly-machines';
|
|
14
|
+
import {
|
|
15
|
+
applyToEveryMachine,
|
|
16
|
+
classifyFlyRequestError,
|
|
17
|
+
createWithReadBeforeRetry,
|
|
18
|
+
describeMachineFailures,
|
|
19
|
+
runFlyctlWithTransientRetry,
|
|
20
|
+
} from '../fly-transient-retry';
|
|
14
21
|
import { machineIsServingRuntimeGateway } from '../runtime-gateway-capacity';
|
|
15
22
|
import {
|
|
16
23
|
RECEIPT_GATEWAY_DRAIN_TIMEOUT,
|
|
@@ -217,14 +224,33 @@ export async function restoreRelaySourceGeneration(input: {
|
|
|
217
224
|
'Execution relay rollback requires exact green and blue Machine identities.',
|
|
218
225
|
);
|
|
219
226
|
}
|
|
220
|
-
|
|
221
|
-
|
|
227
|
+
// Attempt every source Machine even when one fails, so one provider error
|
|
228
|
+
// cannot leave the rest of the retained fleet cordoned and unreported.
|
|
229
|
+
const restored = await applyToEveryMachine({
|
|
230
|
+
machineIds: input.blueMachineIds,
|
|
231
|
+
action: 'uncordon',
|
|
232
|
+
apply: input.uncordon,
|
|
233
|
+
});
|
|
234
|
+
if (restored.failed.length > 0) {
|
|
235
|
+
// Keep the candidate generation admitted: cordoning it beside an
|
|
236
|
+
// incomplete source fleet could drop relay capacity below its minimum.
|
|
237
|
+
// Rerunning rollback converges because uncordon is idempotent.
|
|
238
|
+
throw new Error(
|
|
239
|
+
`Execution relay rollback could not restore ${restored.failed.length}/${input.blueMachineIds.length} source Machine(s) [${restored.failed.map(({ machineId }) => machineId).join(', ')}]; the candidate generation [${input.greenMachineIds.join(', ')}] stays admitted: ${describeMachineFailures('uncordon', restored.failed)}`,
|
|
240
|
+
);
|
|
222
241
|
}
|
|
223
242
|
await Promise.all(input.blueMachineIds.map(input.assertReady));
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
243
|
+
const removed = await applyToEveryMachine({
|
|
244
|
+
machineIds: input.greenMachineIds,
|
|
245
|
+
action: 'cordon',
|
|
246
|
+
apply: input.cordon,
|
|
247
|
+
});
|
|
227
248
|
await Promise.all(input.blueMachineIds.map(input.assertReady));
|
|
249
|
+
if (removed.failed.length > 0) {
|
|
250
|
+
throw new Error(
|
|
251
|
+
`Execution relay rollback restored the source generation but could not cordon ${removed.failed.length}/${input.greenMachineIds.length} candidate Machine(s) [${removed.failed.map(({ machineId }) => machineId).join(', ')}]: ${describeMachineFailures('cordon', removed.failed)}`,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
228
254
|
}
|
|
229
255
|
|
|
230
256
|
function run(command: string, args: string[]): void {
|
|
@@ -237,6 +263,26 @@ function run(command: string, args: string[]): void {
|
|
|
237
263
|
`${command} ${args.join(' ')} failed with ${result.status}.`,
|
|
238
264
|
);
|
|
239
265
|
}
|
|
266
|
+
|
|
267
|
+
/** Cordon and uncordon converge when repeated; retry transient Fly errors. */
|
|
268
|
+
async function setMachineRouting(
|
|
269
|
+
transition: 'cordon' | 'uncordon',
|
|
270
|
+
machineId: string,
|
|
271
|
+
): Promise<void> {
|
|
272
|
+
await runFlyctlWithTransientRetry(
|
|
273
|
+
['machine', transition, machineId, '-a', app],
|
|
274
|
+
{
|
|
275
|
+
operation: 'idempotent-write',
|
|
276
|
+
spawn: spawnSync,
|
|
277
|
+
},
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function releaseFlyClient(): FlyMachinesClient {
|
|
282
|
+
return new FlyMachinesClient(app, requireFlyToken(), fetch, {
|
|
283
|
+
transientRetry: true,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
240
286
|
async function inventory(client: FlyMachinesClient): Promise<FlyMachine[]> {
|
|
241
287
|
return await client.listMachines();
|
|
242
288
|
}
|
|
@@ -309,7 +355,7 @@ async function assertExactReady(machineId: string): Promise<void> {
|
|
|
309
355
|
}
|
|
310
356
|
async function prepare(sha: string): Promise<void> {
|
|
311
357
|
run('bun', productionGatewayImageEnsureArgs('executionRelay', sha));
|
|
312
|
-
const client =
|
|
358
|
+
const client = releaseFlyClient();
|
|
313
359
|
const initial = await inventory(client);
|
|
314
360
|
const existing = candidates(initial, sha);
|
|
315
361
|
const blue = serving(initial);
|
|
@@ -332,6 +378,29 @@ async function prepare(sha: string): Promise<void> {
|
|
|
332
378
|
return;
|
|
333
379
|
}
|
|
334
380
|
}
|
|
381
|
+
const createCandidate = (name: string, source: FlyMachine) =>
|
|
382
|
+
client.createMachine({
|
|
383
|
+
name,
|
|
384
|
+
region: topology.region,
|
|
385
|
+
skip_service_registration: true,
|
|
386
|
+
config: gatewayMachineConfig({
|
|
387
|
+
profile: 'production',
|
|
388
|
+
role: 'execution',
|
|
389
|
+
image: image(sha),
|
|
390
|
+
metadata: {
|
|
391
|
+
deepline_gateway_role: 'execution',
|
|
392
|
+
[EXECUTION_RELAY_ROLLOUT_METADATA]: sha,
|
|
393
|
+
[EXECUTION_RELAY_SOURCE_METADATA]: source.id!,
|
|
394
|
+
fly_process_group: topology.processGroup,
|
|
395
|
+
...(source.config?.metadata?.[
|
|
396
|
+
RUNTIME_GATEWAY_AUTOSCALED_METADATA_KEY
|
|
397
|
+
] === '1' ||
|
|
398
|
+
source.name?.startsWith('execution-relay-autoscale-') === true
|
|
399
|
+
? { [RUNTIME_GATEWAY_AUTOSCALED_METADATA_KEY]: '1' }
|
|
400
|
+
: {}),
|
|
401
|
+
},
|
|
402
|
+
}),
|
|
403
|
+
});
|
|
335
404
|
if (existing.length === 0) {
|
|
336
405
|
if (
|
|
337
406
|
blue.length < topology.minimumMachines ||
|
|
@@ -341,27 +410,17 @@ async function prepare(sha: string): Promise<void> {
|
|
|
341
410
|
'Cannot prepare an execution relay generation without a healthy serving fleet.',
|
|
342
411
|
);
|
|
343
412
|
for (const [index, source] of blue.entries()) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
[EXECUTION_RELAY_SOURCE_METADATA]: source.id!,
|
|
356
|
-
fly_process_group: topology.processGroup,
|
|
357
|
-
...(source.config?.metadata?.[
|
|
358
|
-
RUNTIME_GATEWAY_AUTOSCALED_METADATA_KEY
|
|
359
|
-
] === '1' ||
|
|
360
|
-
source.name?.startsWith('execution-relay-autoscale-') === true
|
|
361
|
-
? { [RUNTIME_GATEWAY_AUTOSCALED_METADATA_KEY]: '1' }
|
|
362
|
-
: {}),
|
|
363
|
-
},
|
|
364
|
-
}),
|
|
413
|
+
const name = candidateName(sha, index);
|
|
414
|
+
// A transient create failure is ambiguous; re-read before any retry
|
|
415
|
+
// so a candidate Fly already created is adopted, never duplicated.
|
|
416
|
+
await createWithReadBeforeRetry({
|
|
417
|
+
create: () => createCandidate(name, source),
|
|
418
|
+
findExisting: async () =>
|
|
419
|
+
candidates(await inventory(client), sha).find(
|
|
420
|
+
(machine) => machine.name === name,
|
|
421
|
+
),
|
|
422
|
+
classify: classifyFlyRequestError,
|
|
423
|
+
options: { label: `Create execution relay candidate ${name}` },
|
|
365
424
|
});
|
|
366
425
|
}
|
|
367
426
|
}
|
|
@@ -379,7 +438,7 @@ async function prepare(sha: string): Promise<void> {
|
|
|
379
438
|
// separately; do not assume the header is the blocker.
|
|
380
439
|
}
|
|
381
440
|
async function activate(sha: string): Promise<void> {
|
|
382
|
-
const client =
|
|
441
|
+
const client = releaseFlyClient();
|
|
383
442
|
const machines = await inventory(client);
|
|
384
443
|
const green = candidates(machines, sha);
|
|
385
444
|
if (
|
|
@@ -409,13 +468,9 @@ async function activate(sha: string): Promise<void> {
|
|
|
409
468
|
machineIdsToUncordon: green
|
|
410
469
|
.filter((machine) => machine.cordoned === true)
|
|
411
470
|
.map((machine) => machine.id!),
|
|
412
|
-
uncordon:
|
|
413
|
-
run('flyctl', ['machine', 'uncordon', machineId, '-a', app]);
|
|
414
|
-
},
|
|
471
|
+
uncordon: (machineId) => setMachineRouting('uncordon', machineId),
|
|
415
472
|
assertReady: assertExactReady,
|
|
416
|
-
cordon:
|
|
417
|
-
run('flyctl', ['machine', 'cordon', machineId, '-a', app]);
|
|
418
|
-
},
|
|
473
|
+
cordon: (machineId) => setMachineRouting('cordon', machineId),
|
|
419
474
|
});
|
|
420
475
|
const refreshed = await inventory(client);
|
|
421
476
|
for (const machineId of sourceMachineIds as string[]) {
|
|
@@ -427,13 +482,13 @@ async function activate(sha: string): Promise<void> {
|
|
|
427
482
|
);
|
|
428
483
|
}
|
|
429
484
|
if (blue.cordoned === false) {
|
|
430
|
-
|
|
485
|
+
await setMachineRouting('cordon', machineId);
|
|
431
486
|
}
|
|
432
487
|
}
|
|
433
488
|
}
|
|
434
489
|
|
|
435
490
|
async function rollback(sha: string): Promise<void> {
|
|
436
|
-
const client =
|
|
491
|
+
const client = releaseFlyClient();
|
|
437
492
|
const current = await inventory(client);
|
|
438
493
|
const green = candidates(current, sha);
|
|
439
494
|
if (
|
|
@@ -467,19 +522,15 @@ async function rollback(sha: string): Promise<void> {
|
|
|
467
522
|
await restoreRelaySourceGeneration({
|
|
468
523
|
greenMachineIds: green.map((machine) => machine.id!),
|
|
469
524
|
blueMachineIds: sourceMachineIds as string[],
|
|
470
|
-
uncordon:
|
|
471
|
-
|
|
472
|
-
},
|
|
473
|
-
cordon: async (machineId) => {
|
|
474
|
-
run('flyctl', ['machine', 'cordon', machineId, '-a', app]);
|
|
475
|
-
},
|
|
525
|
+
uncordon: (machineId) => setMachineRouting('uncordon', machineId),
|
|
526
|
+
cordon: (machineId) => setMachineRouting('cordon', machineId),
|
|
476
527
|
assertReady: assertExactReady,
|
|
477
528
|
});
|
|
478
529
|
}
|
|
479
530
|
/** Remove only a candidate that never received public traffic. This mirrors
|
|
480
531
|
* receipt cleanup so a failed pre-commit proof cannot strand relay Machines. */
|
|
481
532
|
async function cleanup(sha: string): Promise<void> {
|
|
482
|
-
const client =
|
|
533
|
+
const client = releaseFlyClient();
|
|
483
534
|
const targets = candidates(await inventory(client), sha);
|
|
484
535
|
if (targets.some((machine) => !machine.id)) {
|
|
485
536
|
throw new Error(
|
package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/roll-receipt-gateway.ts
CHANGED
|
@@ -21,6 +21,14 @@
|
|
|
21
21
|
import { spawn, spawnSync } from 'node:child_process';
|
|
22
22
|
import { resolve } from 'node:path';
|
|
23
23
|
import { FlyMachinesClient, requireFlyToken } from '../fly-machines';
|
|
24
|
+
import {
|
|
25
|
+
applyToEveryMachine,
|
|
26
|
+
classifyFlyRequestError,
|
|
27
|
+
createWithReadBeforeRetry,
|
|
28
|
+
describeMachineFailures,
|
|
29
|
+
runFlyctlWithTransientRetry,
|
|
30
|
+
runFlyctlWithTransientRetrySync,
|
|
31
|
+
} from '../fly-transient-retry';
|
|
24
32
|
import {
|
|
25
33
|
RECEIPT_GATEWAY_DRAIN_TIMEOUT,
|
|
26
34
|
stopAndDestroyCordonedMachines,
|
|
@@ -144,12 +152,29 @@ export function runReceiptGatewayCommand(
|
|
|
144
152
|
echoStdout?: boolean;
|
|
145
153
|
timeoutMs?: number;
|
|
146
154
|
spawnCommand?: ReceiptGatewayCommandSpawn;
|
|
155
|
+
/**
|
|
156
|
+
* Retry transient Fly API failures of a flyctl command that converges
|
|
157
|
+
* when repeated. `read` may also repeat after a timeout.
|
|
158
|
+
*/
|
|
159
|
+
flyTransientRetry?: 'read' | 'idempotent-write';
|
|
160
|
+
sleep?: (milliseconds: number) => void;
|
|
147
161
|
} = {},
|
|
148
162
|
): string {
|
|
149
163
|
const spawnCommand: ReceiptGatewayCommandSpawn =
|
|
150
164
|
options.spawnCommand ??
|
|
151
165
|
((executable, commandArgs, spawnOptions) =>
|
|
152
166
|
spawnSync(executable, commandArgs, spawnOptions));
|
|
167
|
+
if (options.flyTransientRetry && command === 'flyctl') {
|
|
168
|
+
return runFlyctlWithTransientRetrySync(args, {
|
|
169
|
+
operation: options.flyTransientRetry,
|
|
170
|
+
env,
|
|
171
|
+
timeoutMs: options.timeoutMs,
|
|
172
|
+
echoStdout: options.echoStdout,
|
|
173
|
+
spawn: (executable, commandArgs, spawnOptions) =>
|
|
174
|
+
spawnCommand(executable, commandArgs, spawnOptions),
|
|
175
|
+
...(options.sleep ? { sleep: options.sleep } : {}),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
153
178
|
const result = spawnCommand(command, args, {
|
|
154
179
|
encoding: 'utf8',
|
|
155
180
|
env,
|
|
@@ -204,6 +229,23 @@ function runAsync(
|
|
|
204
229
|
});
|
|
205
230
|
}
|
|
206
231
|
|
|
232
|
+
/** Cordon and uncordon converge when repeated; retry transient Fly errors. */
|
|
233
|
+
async function setMachineRouting(
|
|
234
|
+
transition: 'cordon' | 'uncordon',
|
|
235
|
+
machineId: string,
|
|
236
|
+
): Promise<void> {
|
|
237
|
+
await runFlyctlWithTransientRetry(
|
|
238
|
+
['machine', transition, machineId, '-a', fleet.app],
|
|
239
|
+
{ operation: 'idempotent-write', spawn: spawnSync },
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function releaseFlyClient(): FlyMachinesClient {
|
|
244
|
+
return new FlyMachinesClient(fleet.app, requireFlyToken(), fetch, {
|
|
245
|
+
transientRetry: true,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
207
249
|
function receiptGatewayImage(operationId: string): string {
|
|
208
250
|
return `registry.fly.io/${fleet.app}:git-${operationId}`;
|
|
209
251
|
}
|
|
@@ -269,6 +311,7 @@ function machines(): FlyMachine[] {
|
|
|
269
311
|
{
|
|
270
312
|
echoStdout: false,
|
|
271
313
|
timeoutMs: FLY_MACHINE_INVENTORY_TIMEOUT_MS,
|
|
314
|
+
flyTransientRetry: 'read',
|
|
272
315
|
},
|
|
273
316
|
);
|
|
274
317
|
const parsed: unknown = JSON.parse(output);
|
|
@@ -767,7 +810,7 @@ async function persistCandidatePhase(input: {
|
|
|
767
810
|
candidates: readonly FlyMachine[];
|
|
768
811
|
phase: ReceiptGatewayOperationPhase;
|
|
769
812
|
}): Promise<void> {
|
|
770
|
-
const client =
|
|
813
|
+
const client = releaseFlyClient();
|
|
771
814
|
await Promise.all(
|
|
772
815
|
input.candidates.map(async (candidate) => {
|
|
773
816
|
if (!candidate.id) throw new Error('Receipt candidate has no identity.');
|
|
@@ -814,7 +857,7 @@ async function removeCordoned(operationId: string): Promise<void> {
|
|
|
814
857
|
'Refusing to remove a receipt candidate that received public traffic.',
|
|
815
858
|
);
|
|
816
859
|
}
|
|
817
|
-
const client =
|
|
860
|
+
const client = releaseFlyClient();
|
|
818
861
|
await stopAndDestroyCordonedMachines({
|
|
819
862
|
machineIds: targets.map((machine) => machine.id!).filter(Boolean),
|
|
820
863
|
readMachines: machines,
|
|
@@ -832,7 +875,7 @@ async function removeCordoned(operationId: string): Promise<void> {
|
|
|
832
875
|
/** The public green candidates are the durable Fly operation record. Their
|
|
833
876
|
* source metadata is the only authority for destructive blue retirement. */
|
|
834
877
|
async function drain(operationId: string): Promise<void> {
|
|
835
|
-
const client =
|
|
878
|
+
const client = releaseFlyClient();
|
|
836
879
|
const green = candidatesFor(operationId, await client.listMachines());
|
|
837
880
|
if (
|
|
838
881
|
green.length < fleet.minimumMachines ||
|
|
@@ -889,12 +932,9 @@ async function prepare(operationId: string): Promise<void> {
|
|
|
889
932
|
if (existing.length > 0) {
|
|
890
933
|
assertCandidateSourceGeneration({ candidates: existing, serving: blue });
|
|
891
934
|
}
|
|
892
|
-
const client =
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
if (existing.some((machine) => machine.name === name)) continue;
|
|
896
|
-
if (!source.id) throw new Error('Serving Machine has no identity.');
|
|
897
|
-
await client.createMachine({
|
|
935
|
+
const client = releaseFlyClient();
|
|
936
|
+
const createCandidate = (name: string, sourceId: string) =>
|
|
937
|
+
client.createMachine({
|
|
898
938
|
name,
|
|
899
939
|
region: fleet.primaryRegion,
|
|
900
940
|
skip_service_registration: true,
|
|
@@ -905,13 +945,31 @@ async function prepare(operationId: string): Promise<void> {
|
|
|
905
945
|
metadata: {
|
|
906
946
|
deepline_gateway_role: 'receipt',
|
|
907
947
|
deepline_gateway_rollout: operationId,
|
|
908
|
-
deepline_gateway_source_machine:
|
|
948
|
+
deepline_gateway_source_machine: sourceId,
|
|
909
949
|
[RECEIPT_GATEWAY_OPERATION_PHASE_METADATA_KEY]:
|
|
910
950
|
ReceiptGatewayOperationPhase.Prepared,
|
|
911
951
|
fly_process_group: fleet.processGroup,
|
|
912
952
|
},
|
|
913
953
|
}),
|
|
914
954
|
});
|
|
955
|
+
for (const [index, source] of blue.entries()) {
|
|
956
|
+
const name = candidateName(operationId, index);
|
|
957
|
+
if (existing.some((machine) => machine.name === name)) continue;
|
|
958
|
+
if (!source.id) throw new Error('Serving Machine has no identity.');
|
|
959
|
+
const sourceId = source.id;
|
|
960
|
+
// A transient create failure is ambiguous; re-read before any retry so a
|
|
961
|
+
// candidate Fly already created is adopted, never duplicated. The result
|
|
962
|
+
// is unused (waitForCandidates re-reads), and the create response and the
|
|
963
|
+
// inventory entry are different FlyMachine shapes, so neither narrows T.
|
|
964
|
+
await createWithReadBeforeRetry<unknown>({
|
|
965
|
+
create: () => createCandidate(name, sourceId),
|
|
966
|
+
findExisting: async () =>
|
|
967
|
+
candidatesFor(operationId, await client.listMachines()).find(
|
|
968
|
+
(machine) => machine.name === name,
|
|
969
|
+
),
|
|
970
|
+
classify: classifyFlyRequestError,
|
|
971
|
+
options: { label: `Create receipt gateway candidate ${name}` },
|
|
972
|
+
});
|
|
915
973
|
}
|
|
916
974
|
const ready = await waitForCandidates(operationId, blue.length);
|
|
917
975
|
await assertPublic(blue.map((machine) => machine.id!));
|
|
@@ -1030,8 +1088,13 @@ export async function activateCordonedReceiptCandidates(input: {
|
|
|
1030
1088
|
onRetry: reportGatewayRouteProbeRetry,
|
|
1031
1089
|
});
|
|
1032
1090
|
} catch (error) {
|
|
1033
|
-
|
|
1034
|
-
|
|
1091
|
+
// Attempt every candidate even when one fails, then report every Machine
|
|
1092
|
+
// that could still be admitted.
|
|
1093
|
+
const removed = await applyToEveryMachine({
|
|
1094
|
+
machineIds: input.greenMachineIds,
|
|
1095
|
+
action: 'cordon',
|
|
1096
|
+
apply: input.cordon,
|
|
1097
|
+
});
|
|
1035
1098
|
await input.sleep(POLL_MS);
|
|
1036
1099
|
await waitForGatewayRouteProbe({
|
|
1037
1100
|
description: 'Receipt gateway rollback generation',
|
|
@@ -1039,6 +1102,12 @@ export async function activateCordonedReceiptCandidates(input: {
|
|
|
1039
1102
|
sleep: input.sleep,
|
|
1040
1103
|
onRetry: reportGatewayRouteProbeRetry,
|
|
1041
1104
|
});
|
|
1105
|
+
if (removed.failed.length > 0) {
|
|
1106
|
+
throw new Error(
|
|
1107
|
+
`Receipt gateway candidate activation failed and ${removed.failed.length}/${input.greenMachineIds.length} candidate Machine(s) [${removed.failed.map(({ machineId }) => machineId).join(', ')}] could not be cordoned: ${describeMachineFailures('cordon', removed.failed)}`,
|
|
1108
|
+
{ cause: error },
|
|
1109
|
+
);
|
|
1110
|
+
}
|
|
1042
1111
|
throw error;
|
|
1043
1112
|
}
|
|
1044
1113
|
}
|
|
@@ -1062,7 +1131,21 @@ export async function restoreReceiptGatewaySourceGeneration(input: {
|
|
|
1062
1131
|
'Gateway rollback requires exact green and blue Machine identities.',
|
|
1063
1132
|
);
|
|
1064
1133
|
}
|
|
1065
|
-
|
|
1134
|
+
// Attempt every source Machine even when one fails, so one provider error
|
|
1135
|
+
// cannot leave the rest of the retained fleet cordoned and unreported.
|
|
1136
|
+
const restored = await applyToEveryMachine({
|
|
1137
|
+
machineIds: input.blueMachineIds,
|
|
1138
|
+
action: 'uncordon',
|
|
1139
|
+
apply: input.uncordon,
|
|
1140
|
+
});
|
|
1141
|
+
if (restored.failed.length > 0) {
|
|
1142
|
+
// Keep the candidate generation admitted: cordoning it beside an
|
|
1143
|
+
// incomplete source fleet could drop receipt capacity below its minimum.
|
|
1144
|
+
// Rerunning rollback converges because uncordon is idempotent.
|
|
1145
|
+
throw new Error(
|
|
1146
|
+
`Receipt gateway rollback could not restore ${restored.failed.length}/${input.blueMachineIds.length} source Machine(s) [${restored.failed.map(({ machineId }) => machineId).join(', ')}]; the candidate generation [${input.greenMachineIds.join(', ')}] stays admitted: ${describeMachineFailures('uncordon', restored.failed)}`,
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1066
1149
|
await input.sleep(POLL_MS);
|
|
1067
1150
|
await waitForGatewayRouteProbe({
|
|
1068
1151
|
description: 'Receipt gateway rollback source generation',
|
|
@@ -1070,7 +1153,11 @@ export async function restoreReceiptGatewaySourceGeneration(input: {
|
|
|
1070
1153
|
sleep: input.sleep,
|
|
1071
1154
|
onRetry: reportGatewayRouteProbeRetry,
|
|
1072
1155
|
});
|
|
1073
|
-
|
|
1156
|
+
const removed = await applyToEveryMachine({
|
|
1157
|
+
machineIds: input.greenMachineIds,
|
|
1158
|
+
action: 'cordon',
|
|
1159
|
+
apply: input.cordon,
|
|
1160
|
+
});
|
|
1074
1161
|
await input.sleep(POLL_MS);
|
|
1075
1162
|
await waitForGatewayRouteProbe({
|
|
1076
1163
|
description: 'Receipt gateway restored source generation',
|
|
@@ -1078,6 +1165,11 @@ export async function restoreReceiptGatewaySourceGeneration(input: {
|
|
|
1078
1165
|
sleep: input.sleep,
|
|
1079
1166
|
onRetry: reportGatewayRouteProbeRetry,
|
|
1080
1167
|
});
|
|
1168
|
+
if (removed.failed.length > 0) {
|
|
1169
|
+
throw new Error(
|
|
1170
|
+
`Receipt gateway rollback restored the source generation but could not cordon ${removed.failed.length}/${input.greenMachineIds.length} candidate Machine(s) [${removed.failed.map(({ machineId }) => machineId).join(', ')}]: ${describeMachineFailures('cordon', removed.failed)}`,
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1081
1173
|
}
|
|
1082
1174
|
|
|
1083
1175
|
function assertExactCordonedCandidates(input: {
|
|
@@ -1255,12 +1347,8 @@ async function activate(operationId: string): Promise<void> {
|
|
|
1255
1347
|
uncordonMachineIds: green
|
|
1256
1348
|
.filter((machine) => machine.cordoned === true)
|
|
1257
1349
|
.map((machine) => machine.id!),
|
|
1258
|
-
uncordon: (machineId) =>
|
|
1259
|
-
|
|
1260
|
-
},
|
|
1261
|
-
cordon: (machineId) => {
|
|
1262
|
-
run('flyctl', ['machine', 'cordon', machineId, '-a', fleet.app]);
|
|
1263
|
-
},
|
|
1350
|
+
uncordon: (machineId) => setMachineRouting('uncordon', machineId),
|
|
1351
|
+
cordon: (machineId) => setMachineRouting('cordon', machineId),
|
|
1264
1352
|
assertPublic,
|
|
1265
1353
|
sleep: (milliseconds) =>
|
|
1266
1354
|
new Promise((resolve) => setTimeout(resolve, milliseconds)),
|
|
@@ -1280,7 +1368,7 @@ async function activate(operationId: string): Promise<void> {
|
|
|
1280
1368
|
);
|
|
1281
1369
|
for (const machine of blue) {
|
|
1282
1370
|
if (machine.cordoned === false) {
|
|
1283
|
-
|
|
1371
|
+
await setMachineRouting('cordon', machine.id!);
|
|
1284
1372
|
}
|
|
1285
1373
|
}
|
|
1286
1374
|
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
@@ -1320,12 +1408,8 @@ async function rollback(operationId: string): Promise<void> {
|
|
|
1320
1408
|
await restoreReceiptGatewaySourceGeneration({
|
|
1321
1409
|
greenMachineIds,
|
|
1322
1410
|
blueMachineIds: sourceIds,
|
|
1323
|
-
uncordon: (machineId) =>
|
|
1324
|
-
|
|
1325
|
-
},
|
|
1326
|
-
cordon: (machineId) => {
|
|
1327
|
-
run('flyctl', ['machine', 'cordon', machineId, '-a', fleet.app]);
|
|
1328
|
-
},
|
|
1411
|
+
uncordon: (machineId) => setMachineRouting('uncordon', machineId),
|
|
1412
|
+
cordon: (machineId) => setMachineRouting('cordon', machineId),
|
|
1329
1413
|
assertPublic,
|
|
1330
1414
|
sleep: (milliseconds) =>
|
|
1331
1415
|
new Promise((resolve) => setTimeout(resolve, milliseconds)),
|
package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/runtime-topology.ts
CHANGED
|
@@ -30,6 +30,12 @@ import {
|
|
|
30
30
|
shouldCreateDetachedProcessGroup,
|
|
31
31
|
terminateChildProcessTree,
|
|
32
32
|
} from '../process-tree';
|
|
33
|
+
import {
|
|
34
|
+
classifyFlyCommandError,
|
|
35
|
+
classifyFlyCommandFailure,
|
|
36
|
+
FlyCommandError,
|
|
37
|
+
withFlyTransientRetry,
|
|
38
|
+
} from '../fly-transient-retry';
|
|
33
39
|
|
|
34
40
|
export enum TopologyOperation {
|
|
35
41
|
ReconcilePlatform = 'reconcile-platform',
|
|
@@ -109,6 +115,11 @@ export type RuntimeTopologyCommand = (input: {
|
|
|
109
115
|
args: string[];
|
|
110
116
|
environment: Record<string, string>;
|
|
111
117
|
description: string;
|
|
118
|
+
/**
|
|
119
|
+
* A flyctl command that converges when repeated (a staged secret write of
|
|
120
|
+
* the same values). Transient Fly API failures are retried.
|
|
121
|
+
*/
|
|
122
|
+
flyTransientRetry?: 'idempotent-write';
|
|
112
123
|
}) => void | Promise<void>;
|
|
113
124
|
|
|
114
125
|
/**
|
|
@@ -122,6 +133,7 @@ export type RuntimeTopologyParallelCommand = (input: {
|
|
|
122
133
|
args: string[];
|
|
123
134
|
environment: Record<string, string>;
|
|
124
135
|
description: string;
|
|
136
|
+
flyTransientRetry?: 'idempotent-write';
|
|
125
137
|
}) => Promise<void>;
|
|
126
138
|
|
|
127
139
|
export type RuntimeTopologySpawn = (
|
|
@@ -149,9 +161,13 @@ const activeRuntimeTopologyCommands = new Set<ActiveRuntimeTopologyCommand>();
|
|
|
149
161
|
const runtimeTopologyCancellationSignals: readonly RuntimeTopologyCancellationSignal[] =
|
|
150
162
|
['SIGINT', 'SIGTERM'];
|
|
151
163
|
|
|
164
|
+
/** Set once cancellation is requested so no transient retry starts after it. */
|
|
165
|
+
let runtimeTopologyCancellation: RuntimeTopologyCancellationSignal | undefined;
|
|
166
|
+
|
|
152
167
|
function cancelActiveRuntimeTopologyCommands(
|
|
153
168
|
signal: RuntimeTopologyCancellationSignal,
|
|
154
169
|
): number {
|
|
170
|
+
runtimeTopologyCancellation ??= signal;
|
|
155
171
|
for (const command of activeRuntimeTopologyCommands) command.cancel(signal);
|
|
156
172
|
return activeRuntimeTopologyCommands.size;
|
|
157
173
|
}
|
|
@@ -254,18 +270,61 @@ export function runRuntimeTopologyCommand(
|
|
|
254
270
|
}
|
|
255
271
|
}
|
|
256
272
|
|
|
273
|
+
/** Enough trailing output to classify a flyctl transport failure. */
|
|
274
|
+
const FLY_RETRY_OUTPUT_TAIL_CHARACTERS = 16_384;
|
|
275
|
+
|
|
257
276
|
export async function runRuntimeTopologyAsyncCommand(input: {
|
|
258
277
|
command: string;
|
|
259
278
|
args: string[];
|
|
260
279
|
environment: Record<string, string>;
|
|
261
280
|
description: string;
|
|
281
|
+
flyTransientRetry?: 'idempotent-write';
|
|
262
282
|
}): Promise<void> {
|
|
283
|
+
if (!input.flyTransientRetry || input.command !== 'flyctl') {
|
|
284
|
+
await runRuntimeTopologyAsyncAttempt(input);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const operation = input.flyTransientRetry;
|
|
288
|
+
await withFlyTransientRetry(
|
|
289
|
+
async (attempt) => {
|
|
290
|
+
if (attempt > 1 && runtimeTopologyCancellation) {
|
|
291
|
+
throw new Error(
|
|
292
|
+
`${input.description} was not retried: cancellation requested by ${runtimeTopologyCancellation}.`,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
await runRuntimeTopologyAsyncAttempt({ ...input, operation });
|
|
296
|
+
},
|
|
297
|
+
classifyFlyCommandError,
|
|
298
|
+
{ label: input.description },
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* One child process. With `operation` set, its output is forwarded live and a
|
|
304
|
+
* bounded tail is kept to classify a failure as a transient Fly API error.
|
|
305
|
+
*/
|
|
306
|
+
async function runRuntimeTopologyAsyncAttempt(input: {
|
|
307
|
+
command: string;
|
|
308
|
+
args: string[];
|
|
309
|
+
environment: Record<string, string>;
|
|
310
|
+
description: string;
|
|
311
|
+
operation?: 'idempotent-write';
|
|
312
|
+
}): Promise<void> {
|
|
313
|
+
let outputTail = '';
|
|
314
|
+
const capture = (chunk: Buffer, sink: NodeJS.WriteStream): void => {
|
|
315
|
+
sink.write(chunk);
|
|
316
|
+
outputTail = `${outputTail}${chunk.toString('utf8')}`.slice(
|
|
317
|
+
-FLY_RETRY_OUTPUT_TAIL_CHARACTERS,
|
|
318
|
+
);
|
|
319
|
+
};
|
|
263
320
|
await new Promise<void>((resolve, reject) => {
|
|
264
321
|
const child = spawn(input.command, input.args, {
|
|
265
322
|
env: { ...process.env, ...input.environment },
|
|
266
|
-
stdio: 'inherit',
|
|
323
|
+
stdio: input.operation ? ['ignore', 'pipe', 'pipe'] : 'inherit',
|
|
267
324
|
detached: shouldCreateDetachedProcessGroup(),
|
|
268
325
|
});
|
|
326
|
+
child.stdout?.on('data', (chunk: Buffer) => capture(chunk, process.stdout));
|
|
327
|
+
child.stderr?.on('data', (chunk: Buffer) => capture(chunk, process.stderr));
|
|
269
328
|
const activeCommand: ActiveRuntimeTopologyCommand = {
|
|
270
329
|
cancel: (signal) => {
|
|
271
330
|
if (child.exitCode === null && child.signalCode === null) {
|
|
@@ -301,12 +360,24 @@ export async function runRuntimeTopologyAsyncCommand(input: {
|
|
|
301
360
|
resolve();
|
|
302
361
|
return;
|
|
303
362
|
}
|
|
363
|
+
const message = signal
|
|
364
|
+
? `${input.description} was terminated by ${signal}.`
|
|
365
|
+
: `${input.description} failed with exit code ${status ?? '<unknown>'}.`;
|
|
366
|
+
if (!input.operation) {
|
|
367
|
+
reject(new Error(message));
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
304
370
|
reject(
|
|
305
|
-
new
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
371
|
+
new FlyCommandError({
|
|
372
|
+
message,
|
|
373
|
+
status,
|
|
374
|
+
classification: classifyFlyCommandFailure({
|
|
375
|
+
status,
|
|
376
|
+
signal,
|
|
377
|
+
output: outputTail,
|
|
378
|
+
operation: input.operation,
|
|
379
|
+
}),
|
|
380
|
+
}),
|
|
310
381
|
);
|
|
311
382
|
});
|
|
312
383
|
});
|
|
@@ -376,6 +447,8 @@ async function stageSecrets(input: {
|
|
|
376
447
|
],
|
|
377
448
|
environment: input.environment,
|
|
378
449
|
description: `Stage secrets for ${app}`,
|
|
450
|
+
// Staging the same values again converges; Fly resets are transient.
|
|
451
|
+
flyTransientRetry: 'idempotent-write' as const,
|
|
379
452
|
}));
|
|
380
453
|
await runIndependentTopologyCommands(input, commands);
|
|
381
454
|
}
|