Skip to content

Commit

Permalink
fix(core): fix race condition in task scheduler (#17837)
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Jun 28, 2023
1 parent cbb2ca2 commit 03ffa42
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/nx/src/tasks-runner/tasks-schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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];

Expand Down

1 comment on commit 03ffa42

@vercel
Copy link

@vercel vercel bot commented on 03ffa42 Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.