Skip to content

Commit

Permalink
A better try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed May 25, 2024
1 parent 34c4bbe commit b7413d5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions testrunner/src/testrunners/docker-testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit b7413d5

Please sign in to comment.