From b7413d5de511165dcd32bc259c420dd03e155459 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Sat, 25 May 2024 11:38:13 +0200 Subject: [PATCH] A better try/catch --- testrunner/src/testrunners/docker-testrunner.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/testrunner/src/testrunners/docker-testrunner.js b/testrunner/src/testrunners/docker-testrunner.js index 61e85f0..517b3a1 100644 --- a/testrunner/src/testrunners/docker-testrunner.js +++ b/testrunner/src/testrunners/docker-testrunner.js @@ -11,17 +11,18 @@ import { queueHandler } from '../queue/queuehandler.js'; const { join } = path; export default async function runJob(job) { - const baseWorkingDirectory = nconf.get('workingDirectory') || os.tmpdir(); - const dockerContainer = nconf.get('docker:container'); - const logger = log.getLogger(`sitespeedio.dockertestrunner.${job.id}`); const dockerLogger = log.getLogger( `sitespeedio.dockertestrunner.process.${job.id}` ); - const workingDirectory = join(baseWorkingDirectory, job.queue.name, job.id); - + let workingDirectory; try { logger.info('Start with job'); + const baseWorkingDirectory = nconf.get('workingDirectory') || os.tmpdir(); + const dockerContainer = nconf.get('docker:container'); + + workingDirectory = join(baseWorkingDirectory, job.queue.name, job.id); + await mkdir(workingDirectory, { recursive: true }); const configFileName = `${job.queue.name}-${job.id}-config.json`; const resultFileName = `${job.queue.name}-${job.id}-result.json`; @@ -105,7 +106,9 @@ export default async function runJob(job) { } catch (error) { logger.error('Failed to execute job: %s', error.message, job.data.url); job.log('Job failed:' + error.message); - await cleanupWorkingDirectory(workingDirectory, logger); + if (workingDirectory) { + await cleanupWorkingDirectory(workingDirectory, logger); + } throw error; } }