Skip to content

Runner faster termination #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 29, 2022
9 changes: 4 additions & 5 deletions bin/cml/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -427,7 +427,6 @@ exports.handler = async (opts) => {
await run(opts);
} catch (error) {
await shutdown({ ...opts, error });
throw error;
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down