Skip to content

Commit dcf08a5

Browse files
committed
fix: batch job failure handling (and rollback), batch job end stats
1 parent 50fa678 commit dcf08a5

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

lib/batch/tasks/finalize-job.task.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export function finalizeJobTaskFactory(
1919
process.chdir('../../');
2020

2121
// update batch state
22+
ctx.batch.completed.push(job);
23+
ctx.batch.queue = ctx.batch.queue.filter((j) => j !== job);
24+
2225
if (!ctx.options.preserveQueue) {
23-
ctx.batch.completed.push(job);
24-
ctx.batch.queue = ctx.batch.queue.filter((j) => j !== job);
2526
writeJson(ctx.options.jobPath, ctx.batch);
2627
}
2728

lib/batch/tasks/run-job.task.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export function runJobTaskFactory(
2222
title: `${index} / ${total} - ${getRepoNameFromUrl(job)}`,
2323
rollback: async (ctx: Context, task) => {
2424
// update batch state
25+
task.title = `${task.title} failed`;
26+
ctx.batch.failed.push(job);
27+
ctx.batch.queue = ctx.batch.queue.filter((j) => j !== job);
28+
2529
if (!ctx.options.preserveQueue) {
26-
ctx.batch.failed.push(job);
27-
ctx.batch.queue = ctx.batch.queue.filter((j) => j !== job);
2830
writeJson(ctx.options.jobPath, ctx.batch);
2931
task.title = `${task.title} failed, added to failed jobs`;
30-
} else {
31-
task.title = `${task.title} failed`;
3232
}
3333
},
3434
task: async (ctx: Context, task) => {
@@ -43,6 +43,7 @@ export function runJobTaskFactory(
4343
finalizeJobTaskFactory(job, task),
4444
],
4545
{
46+
exitOnError: true,
4647
rendererOptions: {
4748
collapse: true,
4849
},

lib/utils/process.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,18 @@ export const runner = async (
3636
: 'default',
3737
})
3838
.run(context)
39-
.then(() => {
39+
.then((ctx: Context) => {
4040
const duration = new Date().getTime() - start;
4141
logger.info(`Finished (${formatTime(duration)})`);
42+
const { batch } = ctx;
43+
if (batch.completed.length || batch.failed.length) {
44+
logger.info(
45+
`Batch results, queue: ${batch.queue.length}, completed: ${batch.completed.length}, failed: ${batch.failed.length}`
46+
);
47+
batch.failed.forEach((project, index) => {
48+
logger.error(`[FAILED] ${project}`);
49+
});
50+
}
4251
process.exit(0);
4352
})
4453
.catch((err) => {

0 commit comments

Comments
 (0)