fix(core): fix race condition in task scheduler (#17837)
This commit is contained in:
parent
cbb2ca2819
commit
03ffa422be
@ -25,10 +25,9 @@ export class TasksSchedule {
|
|||||||
private reverseTaskDeps = calculateReverseDeps(this.taskGraph);
|
private reverseTaskDeps = calculateReverseDeps(this.taskGraph);
|
||||||
private reverseProjectGraph = reverse(this.projectGraph);
|
private reverseProjectGraph = reverse(this.projectGraph);
|
||||||
private scheduledBatches: Batch[] = [];
|
private scheduledBatches: Batch[] = [];
|
||||||
|
|
||||||
private scheduledTasks: string[] = [];
|
private scheduledTasks: string[] = [];
|
||||||
|
|
||||||
private completedTasks = new Set<string>();
|
private completedTasks = new Set<string>();
|
||||||
|
private scheduleRequestsExecutionChain = Promise.resolve();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly hasher: TaskHasher,
|
private readonly hasher: TaskHasher,
|
||||||
@ -40,14 +39,9 @@ export class TasksSchedule {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async scheduleNextTasks() {
|
public async scheduleNextTasks() {
|
||||||
if (process.env.NX_BATCH_MODE === 'true') {
|
this.scheduleRequestsExecutionChain =
|
||||||
await this.scheduleBatches();
|
this.scheduleRequestsExecutionChain.then(() => this.scheduleTasks());
|
||||||
}
|
await this.scheduleRequestsExecutionChain;
|
||||||
for (let root of this.notScheduledTaskGraph.roots) {
|
|
||||||
if (this.canBeScheduled(root)) {
|
|
||||||
await this.scheduleTask(root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasTasks() {
|
public hasTasks() {
|
||||||
@ -83,6 +77,17 @@ export class TasksSchedule {
|
|||||||
: null;
|
: 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) {
|
private async scheduleTask(taskId: string) {
|
||||||
const task = this.taskGraph.tasks[taskId];
|
const task = this.taskGraph.tasks[taskId];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user