Skip to content

Commit

Permalink
Merge pull request #19449 from storybookjs/ensure-tasks-terminate
Browse files Browse the repository at this point in the history
Ensure we kill all controllers before exiting
  • Loading branch information
tmeasday authored Oct 12, 2022
2 parents f798003 + 240a06f commit 8c96b5f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ function writeTaskList(statusMap: Map<Task, TaskStatus>) {
async function runTask(task: Task, details: TemplateDetails, optionValues: PassedOptionValues) {
const startTime = new Date();
try {
await task.run(details, optionValues);
const controller = await task.run(details, optionValues);

if (details.junitFilename && !task.junit)
await writeJunitXml(getTaskKey(task), details.key, startTime);

return controller;
} catch (err) {
if (details.junitFilename && !task.junit)
await writeJunitXml(getTaskKey(task), details.key, startTime, err);
Expand Down Expand Up @@ -382,6 +384,7 @@ async function run() {
setUnready(startFromTask);
}

const controllers: AbortController[] = [];
for (let i = 0; i < sortedTasks.length; i += 1) {
const task = sortedTasks[i];
const status = statuses.get(task);
Expand All @@ -398,11 +401,13 @@ async function run() {
writeTaskList(statuses);

try {
await runTask(task, details, {
const controller = await runTask(task, details, {
...optionValues,
// Always debug the final task so we can see it's output fully
debug: sortedTasks[i] === finalTask ? true : optionValues.debug,
});

if (controller) controllers.push(controller);
} catch (err) {
logger.error(`Error running task ${getTaskKey(task)}:`);
logger.error();
Expand Down Expand Up @@ -440,6 +445,9 @@ async function run() {
await new Promise(() => {});
}
}
controllers.forEach((controller) => {
controller.abort();
});
}

return 0;
Expand Down

0 comments on commit 8c96b5f

Please sign in to comment.