Skip to content

Commit fbc16bd

Browse files
committed
Runner faster termination
1 parent b9ac0df commit fbc16bd

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

bin/cml/runner.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,16 @@ const shutdown = async (opts) => {
2121
RUNNER_SHUTTING_DOWN = true;
2222

2323
const { error, cloud } = opts;
24-
const {
25-
name,
26-
workdir = '',
27-
tfResource,
28-
noRetry,
29-
reason,
30-
destroyDelay
31-
} = opts;
24+
const { name, workdir = '', tfResource, noRetry, reason } = opts;
3225
const tfPath = workdir;
3326

3427
const unregisterRunner = async () => {
3528
if (!RUNNER) return;
3629

3730
try {
3831
winston.info(`Unregistering runner ${name}...`);
39-
RUNNER && RUNNER.kill('SIGINT');
4032
await cml.unregisterRunner({ name });
33+
RUNNER && RUNNER.kill('SIGINT');
4134
winston.info('\tSuccess');
4235
} catch (err) {
4336
winston.error(`\tFailed: ${err.message}`);
@@ -81,9 +74,6 @@ const shutdown = async (opts) => {
8174
winston.info('runner status', { reason, status: 'terminated' });
8275
}
8376

84-
winston.info(`waiting ${destroyDelay} seconds before exiting...`);
85-
await sleep(destroyDelay);
86-
8777
if (!cloud) {
8878
try {
8979
await unregisterRunner();
@@ -413,6 +403,7 @@ exports.command = 'runner';
413403
exports.description = 'Launch and register a self-hosted runner';
414404

415405
exports.handler = async (opts) => {
406+
const { destroyDelay } = opts;
416407
if (process.env.RUNNER_NAME) {
417408
winston.warn(
418409
'ignoring RUNNER_NAME environment variable, use CML_RUNNER_NAME or --name instead'
@@ -421,6 +412,8 @@ exports.handler = async (opts) => {
421412
try {
422413
await run(opts);
423414
} catch (error) {
415+
winston.info(`waiting ${destroyDelay} seconds before exiting...`);
416+
await sleep(destroyDelay);
424417
await shutdown({ ...opts, error });
425418
throw error;
426419
}

0 commit comments

Comments
 (0)