Skip to content

Commit 6fd67c6

Browse files
committed
fix(checks): prevent OOM, disable concurrent with more than 100 checks
1 parent ddd8fb0 commit 6fd67c6

File tree

1 file changed

+74
-75
lines changed

1 file changed

+74
-75
lines changed

lib/tasks/run-checks.task.ts

Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -32,85 +32,84 @@ export const runChecksTask: ListrTask = {
3232
}
3333
},
3434
task: async (ctx: Context, task) => {
35-
const checksDefinitionsFromApi = ctx.definitions?.checks ?? [];
36-
const checksDefinitionsFromCli = ctx.options?.checkDefinition
37-
? [JSON.parse(ctx.options.checkDefinition)]
38-
: [];
39-
const checkTasks: any = (
40-
checksDefinitionsFromCli.length
41-
? checksDefinitionsFromCli
42-
: checksDefinitionsFromApi
43-
)
44-
.filter((definition) => {
45-
if (
46-
ctx.options.checkPattern &&
47-
!new RegExp(ctx.options.checkPattern, 'i').test(definition.name)
48-
) {
49-
return false;
50-
}
51-
return definition.type !== CheckType.META;
52-
})
53-
.map((definition) => ({
54-
title: `[${definition.type.padEnd(7, ' ')}] "${definition.name}"`,
55-
skip: async (ctx: Context): Promise<any> => {
56-
if (definition.disabled) {
35+
const checkTasks = buildTasks(ctx);
36+
task.title += `, ${checkTasks.length} applicable checks`;
37+
return task.newListr(checkTasks, {
38+
concurrent: checkTasks?.length < 100,
39+
});
40+
},
41+
};
42+
43+
function buildTasks(ctx: Context) {
44+
const checksDefinitionsFromApi = ctx.definitions?.checks ?? [];
45+
const checksDefinitionsFromCli = ctx.options?.checkDefinition
46+
? [JSON.parse(ctx.options.checkDefinition)]
47+
: [];
48+
return (
49+
checksDefinitionsFromCli.length
50+
? checksDefinitionsFromCli
51+
: checksDefinitionsFromApi
52+
)
53+
.filter((definition) => {
54+
if (
55+
ctx.options.checkPattern &&
56+
!new RegExp(ctx.options.checkPattern, 'i').test(definition.name)
57+
) {
58+
return false;
59+
}
60+
return definition.type !== CheckType.META;
61+
})
62+
.map((definition) => ({
63+
title: `[${definition.type.padEnd(7, ' ')}] "${definition.name}"`,
64+
skip: async (ctx: Context): Promise<any> => {
65+
if (definition.disabled) {
66+
return `${CheckResultSymbol.SKIPPED} [${definition.type.padEnd(
67+
7,
68+
' '
69+
)}] "${definition.name}": DISABLED`;
70+
} else if (definition.projectNamePattern) {
71+
const projectNameRegexp = new RegExp(
72+
definition.projectNamePattern,
73+
resolveActiveFlags(
74+
definition.projectNamePatternFlags,
75+
DEFAULT_PROJECT_NAME_PATTERN_FLAGS
76+
)
77+
);
78+
if (!projectNameRegexp.test(ctx.results.name || '')) {
5779
return `${CheckResultSymbol.SKIPPED} [${definition.type.padEnd(
5880
7,
5981
' '
60-
)}] "${definition.name}": DISABLED`;
61-
} else if (definition.projectNamePattern) {
62-
const projectNameRegexp = new RegExp(
63-
definition.projectNamePattern,
64-
resolveActiveFlags(
65-
definition.projectNamePatternFlags,
66-
DEFAULT_PROJECT_NAME_PATTERN_FLAGS
67-
)
68-
);
69-
if (!projectNameRegexp.test(ctx.results.name || '')) {
70-
return `${CheckResultSymbol.SKIPPED} [${definition.type.padEnd(
71-
7,
72-
' '
73-
)}] "${definition.name}": project ${
74-
ctx.results.name
75-
} doesn't match ${definition.projectNamePattern}`;
76-
} else {
77-
return false;
78-
}
82+
)}] "${definition.name}": project ${
83+
ctx.results.name
84+
} doesn't match ${definition.projectNamePattern}`;
7985
} else {
8086
return false;
8187
}
82-
},
83-
task: (() => {
84-
if (definition.type === CheckType.CONTENT) {
85-
return contentCheckTaskFactory(
86-
definition as ContentCheckDefinition
87-
);
88-
} else if (definition.type === CheckType.XPATH) {
89-
return xpathCheckTaskFactory(
90-
definition as XPathCheckDefinition,
91-
ctx
88+
} else {
89+
return false;
90+
}
91+
},
92+
task: (() => {
93+
if (definition.type === CheckType.CONTENT) {
94+
return contentCheckTaskFactory(definition as ContentCheckDefinition);
95+
} else if (definition.type === CheckType.XPATH) {
96+
return xpathCheckTaskFactory(definition as XPathCheckDefinition, ctx);
97+
} else if (definition.type === CheckType.SIZE) {
98+
return sizeCheckTaskFactory(definition);
99+
} else if (definition.type === CheckType.FILE) {
100+
return fileCheckTaskFactory(definition);
101+
} else if (definition.type === CheckType.JSON) {
102+
return jsonCheckTaskFactory(definition);
103+
} else {
104+
return function unknownCheckTask(
105+
ctx: Context,
106+
task: ListrTaskWrapper<Context, ListrDefaultRenderer>
107+
) {
108+
task.skip(
109+
`Implementation for a check with type "${definition.type}" not found`
92110
);
93-
} else if (definition.type === CheckType.SIZE) {
94-
return sizeCheckTaskFactory(definition);
95-
} else if (definition.type === CheckType.FILE) {
96-
return fileCheckTaskFactory(definition);
97-
} else if (definition.type === CheckType.JSON) {
98-
return jsonCheckTaskFactory(definition);
99-
} else {
100-
return function unknownCheckTask(
101-
ctx: Context,
102-
task: ListrTaskWrapper<Context, ListrDefaultRenderer>
103-
) {
104-
task.skip(
105-
`Implementation for a check with type "${definition.type}" not found`
106-
);
107-
};
108-
}
109-
})(),
110-
}));
111-
112-
return task.newListr(checkTasks, {
113-
concurrent: true,
114-
});
115-
},
116-
};
111+
};
112+
}
113+
})(),
114+
}));
115+
}

0 commit comments

Comments
 (0)