@@ -21,7 +21,15 @@ const shutdown = async (opts) => {
21
21
RUNNER_SHUTTING_DOWN = true ;
22
22
23
23
const { error, cloud } = opts ;
24
- const { name, workdir = '' , tfResource, noRetry, reason } = opts ;
24
+ const {
25
+ name,
26
+ workdir = '' ,
27
+ tfResource,
28
+ noRetry,
29
+ reason,
30
+ destroyDelay,
31
+ destroyDelayed
32
+ } = opts ;
25
33
const tfPath = workdir ;
26
34
27
35
const unregisterRunner = async ( ) => {
@@ -61,6 +69,11 @@ const shutdown = async (opts) => {
61
69
const destroyTerraform = async ( ) => {
62
70
if ( ! tfResource ) return ;
63
71
72
+ if ( destroyDelayed ) {
73
+ winston . info ( `Waiting ${ destroyDelay } seconds to destroy` ) ;
74
+ await sleep ( destroyDelay ) ;
75
+ }
76
+
64
77
try {
65
78
winston . debug ( await tf . destroy ( { dir : tfPath } ) ) ;
66
79
} catch ( err ) {
@@ -403,7 +416,6 @@ exports.command = 'runner';
403
416
exports . description = 'Launch and register a self-hosted runner' ;
404
417
405
418
exports . handler = async ( opts ) => {
406
- const { destroyDelay } = opts ;
407
419
if ( process . env . RUNNER_NAME ) {
408
420
winston . warn (
409
421
'ignoring RUNNER_NAME environment variable, use CML_RUNNER_NAME or --name instead'
@@ -412,10 +424,7 @@ exports.handler = async (opts) => {
412
424
try {
413
425
await run ( opts ) ;
414
426
} catch ( error ) {
415
- winston . info ( `waiting ${ destroyDelay } seconds before exiting...` ) ;
416
- await sleep ( destroyDelay ) ;
417
- await shutdown ( { ...opts , error } ) ;
418
- throw error ;
427
+ await shutdown ( { ...opts , error, destroyDelayed : true } ) ;
419
428
}
420
429
} ;
421
430
0 commit comments