Skip to content

Commit 216cd33

Browse files
committed
delayed destroy
1 parent fbc16bd commit 216cd33

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

bin/cml/runner.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ const shutdown = async (opts) => {
2121
RUNNER_SHUTTING_DOWN = true;
2222

2323
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;
2533
const tfPath = workdir;
2634

2735
const unregisterRunner = async () => {
@@ -61,6 +69,11 @@ const shutdown = async (opts) => {
6169
const destroyTerraform = async () => {
6270
if (!tfResource) return;
6371

72+
if (destroyDelayed) {
73+
winston.info(`Waiting ${destroyDelay} seconds to destroy`);
74+
await sleep(destroyDelay);
75+
}
76+
6477
try {
6578
winston.debug(await tf.destroy({ dir: tfPath }));
6679
} catch (err) {
@@ -403,7 +416,6 @@ exports.command = 'runner';
403416
exports.description = 'Launch and register a self-hosted runner';
404417

405418
exports.handler = async (opts) => {
406-
const { destroyDelay } = opts;
407419
if (process.env.RUNNER_NAME) {
408420
winston.warn(
409421
'ignoring RUNNER_NAME environment variable, use CML_RUNNER_NAME or --name instead'
@@ -412,10 +424,7 @@ exports.handler = async (opts) => {
412424
try {
413425
await run(opts);
414426
} 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 });
419428
}
420429
};
421430

0 commit comments

Comments
 (0)