fix(core): fix race condition in task scheduler (#17837)

This commit is contained in:
Leosvel Pérez Espinosa 2023-06-28 16:48:55 +01:00 committed by GitHub
parent cbb2ca2819
commit 03ffa422be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,10 +25,9 @@ export class TasksSchedule {
private reverseTaskDeps = calculateReverseDeps(this.taskGraph);
private reverseProjectGraph = reverse(this.projectGraph);
private scheduledBatches: Batch[] = [];
private scheduledTasks: string[] = [];
private completedTasks = new Set<string>();
private scheduleRequestsExecutionChain = Promise.resolve();
constructor(
private readonly hasher: TaskHasher,
@ -40,14 +39,9 @@ export class TasksSchedule {
) {}
public async scheduleNextTasks() {
if (process.env.NX_BATCH_MODE === 'true') {
await this.scheduleBatches();
}
for (let root of this.notScheduledTaskGraph.roots) {
if (this.canBeScheduled(root)) {
await this.scheduleTask(root);
}
}
this.scheduleRequestsExecutionChain =
this.scheduleRequestsExecutionChain.then(() => this.scheduleTasks());
await this.scheduleRequestsExecutionChain;
}
public hasTasks() {
@ -83,6 +77,17 @@ export class TasksSchedule {
: null;
}
private async scheduleTasks() {
if (process.env.NX_BATCH_MODE === 'true') {
await this.scheduleBatches();
}
for (let root of this.notScheduledTaskGraph.roots) {
if (this.canBeScheduled(root)) {
await this.scheduleTask(root);
}
}
}
private async scheduleTask(taskId: string) {
const task = this.taskGraph.tasks[taskId];