@@ -49,21 +49,32 @@ const MONITOR_STATS_LENGTH_MAX = envToInt(
49
49
100 ,
50
50
) ;
51
51
52
+ log . debug ( "configuration:" , {
53
+ ASYNC_CACHE_MAX ,
54
+ ASYNC_CACHE_TTL_S ,
55
+ MONITOR_INTERVAL_S ,
56
+ MONITOR_STATS_LENGTH_MAX ,
57
+ } ) ;
58
+
52
59
const asyncCache = new LRU < string , ExecuteCodeOutputAsync > ( {
53
60
max : ASYNC_CACHE_MAX ,
54
61
ttl : 1000 * ASYNC_CACHE_TTL_S ,
55
- ttlAutopurge : true ,
56
- allowStale : true ,
57
62
updateAgeOnGet : true ,
58
63
updateAgeOnHas : true ,
59
64
} ) ;
60
65
66
+ function truncStats ( obj ?: ExecuteCodeOutputAsync ) {
67
+ if ( Array . isArray ( obj ?. stats ) ) {
68
+ // truncate to $MONITOR_STATS_LENGTH_MAX, by discarding the inital entries
69
+ obj . stats = obj . stats . slice ( obj . stats . length - MONITOR_STATS_LENGTH_MAX ) ;
70
+ }
71
+ }
72
+
61
73
function asyncCacheUpdate ( job_id : string , upd ) {
62
74
const obj = asyncCache . get ( job_id ) ;
63
75
if ( Array . isArray ( obj ?. stats ) && Array . isArray ( upd . stats ) ) {
64
76
obj . stats . push ( ...upd . stats ) ;
65
- // truncate to $MONITOR_STATS_LENGTH_MAX, by discarding the inital entries
66
- obj . stats = obj . stats . slice ( obj . stats . length - MONITOR_STATS_LENGTH_MAX ) ;
77
+ truncStats ( obj ) ;
67
78
}
68
79
asyncCache . set ( job_id , { ...obj , ...upd } ) ;
69
80
}
@@ -324,7 +335,7 @@ function doSpawn(
324
335
let stderr_is_done = false ;
325
336
let stdout_is_done = false ;
326
337
let killed = false ;
327
- let callback_done = false ;
338
+ let callback_done = false ; // set in "finish", which is also called in a timeout
328
339
let timer : NodeJS . Timeout | undefined = undefined ;
329
340
330
341
// periodically check up on the child process tree and record stats
@@ -360,6 +371,7 @@ function doSpawn(
360
371
cpu_pct : pct_cpu ,
361
372
cpu_secs,
362
373
} ) ;
374
+ truncStats ( obj ) ;
363
375
asyncCache . set ( job_id , obj ) ;
364
376
365
377
// initially, we record more frequently, but then we space it out up until the interval (probably 1 minute)
0 commit comments