@@ -41,7 +41,7 @@ const shutdown = async (opts) => {
4141 RUNNER_SHUTTING_DOWN = true ;
4242
4343 const { error, cloud } = opts ;
44- const { name, workdir = '' , tfResource, noRetry } = opts ;
44+ const { name, workdir = '' , tfResource, noRetry, reason } = opts ;
4545 const tfPath = workdir ;
4646
4747 const unregisterRunner = async ( ) => {
@@ -95,10 +95,14 @@ const shutdown = async (opts) => {
9595 }
9696 } ;
9797
98+ if ( error ) console . log ( error ) ;
9899 console . log (
99- JSON . stringify ( { level : error ? 'error' : 'info' , status : 'terminated' } )
100+ JSON . stringify ( {
101+ level : error ? 'error' : 'info' ,
102+ status : 'terminated' ,
103+ reason
104+ } )
100105 ) ;
101- if ( error ) console . error ( error ) ;
102106 await sleep ( RUNNER_DESTROY_DELAY ) ;
103107
104108 if ( cloud ) {
@@ -273,14 +277,18 @@ const runLocal = async (opts) => {
273277
274278 proc . stderr . on ( 'data' , dataHandler ) ;
275279 proc . stdout . on ( 'data' , dataHandler ) ;
276- proc . on ( 'uncaughtException' , ( ) => shutdown ( opts ) ) ;
277- proc . on ( 'disconnect' , ( ) => shutdown ( opts ) ) ;
278- proc . on ( 'exit' , ( ) => shutdown ( opts ) ) ;
280+ proc . on ( 'uncaughtException' , ( ) =>
281+ shutdown ( { ...opts , reason : 'proc_uncaughtException' } )
282+ ) ;
283+ proc . on ( 'disconnect' , ( ) => shutdown ( { ...opts , reason : 'proc_disconnect' } ) ) ;
284+ proc . on ( 'exit' , ( ) => shutdown ( { ...opts , reason : 'proc_exit' } ) ) ;
279285
280286 if ( ! noRetry ) {
281287 try {
282288 console . log ( `EC2 id ${ await SpotNotifier . instanceId ( ) } ` ) ;
283- SpotNotifier . on ( 'termination' , ( ) => shutdown ( opts ) ) ;
289+ SpotNotifier . on ( 'termination' , ( ) =>
290+ shutdown ( { ...opts , reason : 'spot_termination' } )
291+ ) ;
284292 SpotNotifier . start ( ) ;
285293 } catch ( err ) {
286294 console . log ( 'SpotNotifier can not be started.' ) ;
@@ -290,7 +298,7 @@ const runLocal = async (opts) => {
290298 if ( parseInt ( idleTimeout ) !== 0 ) {
291299 const watcher = setInterval ( ( ) => {
292300 RUNNER_TIMEOUT_TIMER > idleTimeout &&
293- shutdown ( opts ) &&
301+ shutdown ( { ... opts , reason : `timeout: ${ idleTimeout } ` } ) &&
294302 clearInterval ( watcher ) ;
295303
296304 if ( ! RUNNER_JOBS_RUNNING . length ) RUNNER_TIMEOUT_TIMER ++ ;
@@ -304,7 +312,8 @@ const runLocal = async (opts) => {
304312 new Date ( ) . getTime ( ) - new Date ( job . date ) . getTime ( ) >
305313 GH_5_MIN_TIMEOUT
306314 )
307- shutdown ( opts ) && clearInterval ( watcher ) ;
315+ shutdown ( { ...opts , reason : 'timeout:72h' } ) &&
316+ clearInterval ( watcher ) ;
308317 } ) ;
309318 } , 60 * 1000 ) ;
310319 }
@@ -313,9 +322,9 @@ const runLocal = async (opts) => {
313322} ;
314323
315324const run = async ( opts ) => {
316- process . on ( 'SIGTERM' , ( ) => shutdown ( opts ) ) ;
317- process . on ( 'SIGINT' , ( ) => shutdown ( opts ) ) ;
318- process . on ( 'SIGQUIT' , ( ) => shutdown ( opts ) ) ;
325+ process . on ( 'SIGTERM' , ( ) => shutdown ( { ... opts , reason : 'SIGTERM' } ) ) ;
326+ process . on ( 'SIGINT' , ( ) => shutdown ( { ... opts , reason : 'SIGINT' } ) ) ;
327+ process . on ( 'SIGQUIT' , ( ) => shutdown ( { ... opts , reason : 'SIGQUIT' } ) ) ;
319328
320329 opts . workdir = RUNNER_PATH ;
321330 const {
0 commit comments