diff --git a/bin/cml/runner.js b/bin/cml/runner.js index 531866607..2812e07a5 100755 --- a/bin/cml/runner.js +++ b/bin/cml/runner.js @@ -37,8 +37,8 @@ const shutdown = async (opts) => { try { winston.info(`Unregistering runner ${name}...`); - RUNNER && RUNNER.kill('SIGINT'); await cml.unregisterRunner({ name }); + RUNNER && RUNNER.kill('SIGINT'); winston.info('\tSuccess'); } catch (err) { winston.error(`\tFailed: ${err.message}`); @@ -69,6 +69,9 @@ const shutdown = async (opts) => { const destroyTerraform = async () => { if (!tfResource) return; + winston.info(`Waiting ${destroyDelay} seconds to destroy`); + await sleep(destroyDelay); + try { winston.debug(await tf.destroy({ dir: tfPath })); } catch (err) { @@ -82,9 +85,6 @@ const shutdown = async (opts) => { winston.info('runner status', { reason, status: 'terminated' }); } - winston.info(`waiting ${destroyDelay} seconds before exiting...`); - await sleep(destroyDelay); - if (!cloud) { try { await unregisterRunner(); @@ -427,7 +427,6 @@ exports.handler = async (opts) => { await run(opts); } catch (error) { await shutdown({ ...opts, error }); - throw error; } }; diff --git a/src/cml.js b/src/cml.js index 060900622..76f6698f9 100755 --- a/src/cml.js +++ b/src/cml.js @@ -339,7 +339,9 @@ class CML { } async unregisterRunner(opts = {}) { - const { id: runnerId } = await this.runnerByName(opts); + const { id: runnerId } = (await this.runnerByName(opts)) || {}; + if (!runnerId) throw new Error(`Runner not found`); + return await getDriver(this).unregisterRunner({ runnerId, ...opts }); }