Skip to content

Commit

Permalink
feat(misc): add the ability to vary parallel between tasks runner inv…
Browse files Browse the repository at this point in the history
…ocations
  • Loading branch information
vsavkin committed Feb 27, 2023
1 parent 17e6bde commit 825ba04
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions e2e/nx-run/src/invoke-runner.test.ts
Expand Up @@ -46,8 +46,8 @@ describe('Invoke Runner', () => {
async function main(){
const r = await initTasksRunner({});
await r.invoke([{id: '${mylib}:prebuild', target: {project: '${mylib}', target: 'prebuild'}, overrides: {__overrides_unparsed__: ''}}]);
await r.invoke([{id: '${mylib}:build', target: {project: '${mylib}', target: 'build'}, overrides: {__overrides_unparsed__: ''}}]);
await r.invoke({tasks: [{id: '${mylib}:prebuild', target: {project: '${mylib}', target: 'prebuild'}, overrides: {__overrides_unparsed__: ''}}]});
await r.invoke({tasks: [{id: '${mylib}:build', target: {project: '${mylib}', target: 'build'}, overrides: {__overrides_unparsed__: ''}}]});
}
main().then(q => {
Expand Down
17 changes: 9 additions & 8 deletions packages/nx/src/tasks-runner/init-tasks-runner.ts
Expand Up @@ -16,31 +16,32 @@ export async function initTasksRunner(nxArgs: NxArgs) {
}
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
return {
invoke: async (
tasks: Task[]
): Promise<{ status: number; taskGraph: TaskGraph }> => {
invoke: async (opts: {
tasks: Task[];
parallel: number;
}): Promise<{ status: number; taskGraph: TaskGraph }> => {
performance.mark('command-execution-begins');
const lifeCycle = new InvokeRunnerTerminalOutputLifeCycle(tasks);

const taskGraph = {
roots: tasks.map((task) => task.id),
tasks: tasks.reduce((acc, task) => {
roots: opts.tasks.map((task) => task.id),
tasks: opts.tasks.reduce((acc, task) => {
acc[task.id] = task;
return acc;
}, {} as any),
dependencies: tasks.reduce((acc, task) => {
dependencies: opts.tasks.reduce((acc, task) => {
acc[task.id] = [];
return acc;
}, {} as any),
};

const status = await invokeTasksRunner({
tasks,
tasks: opts.tasks,
projectGraph,
taskGraph,
lifeCycle,
nxJson,
nxArgs,
nxArgs: { ...nxArgs, parallel: opts.parallel },
loadDotEnvFiles: true,
initiatingProject: null,
});
Expand Down
Expand Up @@ -18,8 +18,8 @@ export class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle {
bodyLines: this.tasks.map(
(task) =>
`- Task ${task.id} ${
task.overrides.__overrides_unparsed__
? `Overrides: ${task.overrides.__overrides_unparsed__}`
task.overrides.__overrides_unparsed__.length > 0
? `Overrides: ${task.overrides.__overrides_unparsed__.join(' ')}`
: ''
}`
),
Expand All @@ -34,8 +34,8 @@ export class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle {
const cached = this.cachedTasks.indexOf(task) !== -1;
const failed = this.failedTasks.indexOf(task) !== -1;
return `- Task ${task.id} ${
task.overrides.__overrides_unparsed__
? `Overrides: ${task.overrides.__overrides_unparsed__}`
task.overrides.__overrides_unparsed__.length > 0
? `Overrides: ${task.overrides.__overrides_unparsed__.join(' ')}`
: ''
} ${cached ? 'CACHED' : ''} ${failed ? 'FAILED' : ''}`;
});
Expand Down

0 comments on commit 825ba04

Please sign in to comment.