Skill Tracer
Skills › Archify › archify › delivery-update-child.mjs

delivery-update-child.mjs

26 lines · archify/scripts/delivery-update-child.mjs at a406594

1#!/usr/bin/env node
2
3import { checkForUpdate } from './check-update.mjs';
4
5// The parent can be busy in synchronous renderer work. Enforce its original
6// deadline here, in a separate event loop, so cache work cannot continue late.
7if (!/^\d{1,30}$/.test(process.argv[2] || '')) process.exit(1);
8const deadlineAt = BigInt(process.argv[2]);
9const remainingMs = Number(deadlineAt - process.hrtime.bigint()) / 1_000_000;
10if (remainingMs <= 0) process.exit(1);
11const deadlineTimer = setTimeout(() => process.kill(process.pid, 'SIGKILL'), remainingMs);
12deadlineTimer.unref();
14const result = await checkForUpdate({
15 ...(process.env.ARCHIFY_UPDATE_RELEASE_PATH
16 ? { releasePath: process.env.ARCHIFY_UPDATE_RELEASE_PATH } : {}),
17 ...(process.env.ARCHIFY_UPDATE_CACHE_DIRECTORY
18 ? { cacheDirectory: process.env.ARCHIFY_UPDATE_CACHE_DIRECTORY } : {}),
19 // Leave time to record a failed fetch, so a slow network backs off instead
20 // of being killed before its result reaches the cache.
21 timeoutMs: Math.max(1, Math.floor(remainingMs - 150)),
22 // Recompute the remaining fetch budget after cache preparation, so that
23 // startup work cannot consume the failure-recording reserve unnoticed.
24 fetchDeadlineNs: deadlineAt - 150_000_000n,
25});
26process.stdout.write(`${JSON.stringify(result)}\n`);