@@ -7,21 +7,20 @@ const DEFAULT_HEARTBEAT_INTERVAL_MS = 30_000;
77
88type HeartbeatActivity = "build" | "pull" ;
99
10- function heartbeatChildScript ( activity : HeartbeatActivity ) : string {
11- return [
12- "const intervalMs = Number(process.argv[1]);" ,
13- "const parentPid = Number(process.argv[2]);" ,
14- "const startedAt = Date.now();" ,
15- "const stop = () => process.exit(0);" ,
16- 'process.on("SIGINT", stop);' ,
17- 'process.on("SIGTERM", stop);' ,
18- "setInterval(() => {" ,
19- " try { process.kill(parentPid, 0); } catch { stop(); return; }" ,
20- " const elapsedSeconds = Math.max(0, Math.round((Date.now() - startedAt) / 1000));" ,
21- ` process.stdout.write(\` ⏳ Still working on sandbox base image ${ activity } … (\${elapsedSeconds}s elapsed)\\n\`);` ,
22- "}, intervalMs);" ,
23- ] . join ( "\n" ) ;
24- }
10+ const HEARTBEAT_CHILD_SCRIPT = [
11+ "const intervalMs = Number(process.argv[1]);" ,
12+ "const parentPid = Number(process.argv[2]);" ,
13+ "const activity = process.argv[3];" ,
14+ "const startedAt = Date.now();" ,
15+ "const stop = () => process.exit(0);" ,
16+ 'process.on("SIGINT", stop);' ,
17+ 'process.on("SIGTERM", stop);' ,
18+ "setInterval(() => {" ,
19+ " try { process.kill(parentPid, 0); } catch { stop(); return; }" ,
20+ " const elapsedSeconds = Math.max(0, Math.round((Date.now() - startedAt) / 1000));" ,
21+ " process.stdout.write(` ⏳ Still working on sandbox base image ${activity}… (${elapsedSeconds}s elapsed)\\n`);" ,
22+ "}, intervalMs);" ,
23+ ] . join ( "\n" ) ;
2524
2625type SpawnHeartbeat = typeof spawn ;
2726
@@ -48,9 +47,10 @@ export function withLocalBuildHeartbeat<T>(
4847 options . nodeExecutable ?? process . execPath ,
4948 [
5049 "-e" ,
51- heartbeatChildScript ( options . activity ?? "build" ) ,
50+ HEARTBEAT_CHILD_SCRIPT ,
5251 String ( intervalMs ) ,
5352 String ( options . parentPid ?? process . pid ) ,
53+ options . activity ?? "build" ,
5454 ] ,
5555 { env : { } , stdio : [ "ignore" , "inherit" , "inherit" ] } ,
5656 ) ;
0 commit comments