refactor(ngcc): rename `TaskQueue#markTaskCompleted()` to `markAsCompleted()` (#36626)

Rename the `markTaskCompleted()` method to be consistent with the other
similar methods of `TaskQueue` (`markAsFailed()` and
`markAsUnprocessed()`).

PR Close #36626
This commit is contained in:
George Kalpakas 2020-04-29 21:28:09 +03:00 committed by Andrew Kushnir
parent 4665c35453
commit 16039d837e
8 changed files with 49 additions and 49 deletions

View File

@ -215,7 +215,7 @@ export class ClusterMaster {
this.onTaskCompleted(task, msg.outcome, msg.message);
this.taskQueue.markTaskCompleted(task);
this.taskQueue.markAsCompleted(task);
this.taskAssignments.set(workerId, null);
this.maybeDistributeWork();
}

View File

@ -32,7 +32,7 @@ export abstract class SingleProcessorExecutorBase {
while (!taskQueue.allTasksCompleted) {
const task = taskQueue.getNextTask()!;
compile(task);
taskQueue.markTaskCompleted(task);
taskQueue.markAsCompleted(task);
}
const duration = Math.round((Date.now() - startTime) / 1000);

View File

@ -108,7 +108,7 @@ export interface TaskQueue {
*
* @param task The task to mark as completed.
*/
markTaskCompleted(task: Task): void;
markAsCompleted(task: Task): void;
/**
* Mark a task as failed.

View File

@ -37,7 +37,7 @@ export abstract class BaseTaskQueue implements TaskQueue {
break;
}
// We are skipping this task so mark it as complete
this.markTaskCompleted(nextTask);
this.markAsCompleted(nextTask);
const failedTask = this.tasksToSkip.get(nextTask)!;
this.logger.warn(`Skipping processing of ${nextTask.entryPoint.name} because its dependency ${
failedTask.entryPoint.name} failed to compile.`);
@ -46,15 +46,7 @@ export abstract class BaseTaskQueue implements TaskQueue {
return nextTask;
}
markAsFailed(task: Task) {
if (this.dependencies.has(task)) {
for (const dependentTask of this.dependencies.get(task)!) {
this.skipDependentTasks(dependentTask, task);
}
}
}
markTaskCompleted(task: Task): void {
markAsCompleted(task: Task): void {
if (!this.inProgressTasks.has(task)) {
throw new Error(
`Trying to mark task that was not in progress as completed: ${stringifyTask(task)}`);
@ -63,6 +55,14 @@ export abstract class BaseTaskQueue implements TaskQueue {
this.inProgressTasks.delete(task);
}
markAsFailed(task: Task): void {
if (this.dependencies.has(task)) {
for (const dependentTask of this.dependencies.get(task)!) {
this.skipDependentTasks(dependentTask, task);
}
}
}
markAsUnprocessed(task: Task): void {
if (!this.inProgressTasks.has(task)) {
throw new Error(

View File

@ -41,8 +41,8 @@ export class ParallelTaskQueue extends BaseTaskQueue {
return nextTask;
}
markTaskCompleted(task: Task): void {
super.markTaskCompleted(task);
markAsCompleted(task: Task): void {
super.markAsCompleted(task);
if (!this.dependencies.has(task)) {
return;

View File

@ -44,7 +44,7 @@ describe('SingleProcessExecutor', () => {
tasksCount--;
return {};
},
markTaskCompleted(_task: Task) {},
markAsCompleted(_task: Task) {},
};
};

View File

@ -51,7 +51,7 @@ describe('ParallelTaskQueue', () => {
*/
const processNextTask = (queue: TaskQueue): ReturnType<TaskQueue['getNextTask']> => {
const task = queue.getNextTask();
if (task !== null) queue.markTaskCompleted(task);
if (task !== null) queue.markAsCompleted(task);
return task;
};
@ -82,11 +82,11 @@ describe('ParallelTaskQueue', () => {
const task3 = queue.getNextTask()!;
expect(queue.allTasksCompleted).toBe(false);
queue.markTaskCompleted(task1);
queue.markTaskCompleted(task3);
queue.markAsCompleted(task1);
queue.markAsCompleted(task3);
expect(queue.allTasksCompleted).toBe(false); // The second task is still in progress.
queue.markTaskCompleted(task2);
queue.markAsCompleted(task2);
expect(queue.allTasksCompleted).toBe(true);
});
@ -156,18 +156,18 @@ describe('ParallelTaskQueue', () => {
expect(queue.getNextTask()).toBe(null);
// Unblock typings task for entry-point #1 and non-typings task for entry-point #0
queue.markTaskCompleted(tasks[0]);
queue.markAsCompleted(tasks[0]);
expect(queue.getNextTask()).toBe(tasks[2]);
expect(queue.getNextTask()).toBe(tasks[1]);
// The non-typings task for entry-point #1 is blocked on the typings task
expect(queue.getNextTask()).toBe(null);
queue.markTaskCompleted(tasks[1]);
queue.markAsCompleted(tasks[1]);
// Still blocked because we only completed a non-blocking task
expect(queue.getNextTask()).toBe(null);
// Finally, unblock non-typings task for entry-point #1
queue.markTaskCompleted(tasks[2]);
queue.markAsCompleted(tasks[2]);
expect(queue.getNextTask()).toBe(tasks[3]);
});
@ -262,7 +262,7 @@ describe('ParallelTaskQueue', () => {
});
});
describe('markTaskCompleted()', () => {
describe('markAsCompleted()', () => {
it('should mark a task as completed', () => {
const {queue} = createQueue(2);
@ -270,8 +270,8 @@ describe('ParallelTaskQueue', () => {
const task2 = queue.getNextTask()!;
expect(queue.allTasksCompleted).toBe(false);
queue.markTaskCompleted(task1);
queue.markTaskCompleted(task2);
queue.markAsCompleted(task1);
queue.markAsCompleted(task2);
expect(queue.allTasksCompleted).toBe(true);
});
@ -279,7 +279,7 @@ describe('ParallelTaskQueue', () => {
const {tasks, queue} = createQueue(3);
queue.getNextTask();
expect(() => queue.markTaskCompleted(tasks[2]))
expect(() => queue.markAsCompleted(tasks[2]))
.toThrowError(
`Trying to mark task that was not in progress as completed: ` +
`{entryPoint: entry-point-2, formatProperty: prop-0, processDts: true}`);
@ -300,14 +300,14 @@ describe('ParallelTaskQueue', () => {
expect(queue.getNextTask()).toBe(null);
// Once task #0 is completed, task #1 is unblocked.
queue.markTaskCompleted(tasks[0]);
queue.markAsCompleted(tasks[0]);
expect(queue.getNextTask()).toBe(tasks[1]);
// Task #2 is still blocked on #1.
expect(queue.getNextTask()).toBe(null);
// Once task #1 is completed, task #2 is unblocked.
queue.markTaskCompleted(tasks[1]);
queue.markAsCompleted(tasks[1]);
expect(queue.getNextTask()).toBe(tasks[2]);
});
});
@ -321,13 +321,13 @@ describe('ParallelTaskQueue', () => {
expect(queue.allTasksCompleted).toBe(false);
queue.markAsUnprocessed(task1);
queue.markTaskCompleted(task2);
queue.markAsCompleted(task2);
expect(queue.allTasksCompleted).toBe(false);
expect(queue.getNextTask()).toBe(task1);
expect(queue.allTasksCompleted).toBe(false);
queue.markTaskCompleted(task1);
queue.markAsCompleted(task1);
expect(queue.allTasksCompleted).toBe(true);
});
@ -390,7 +390,7 @@ describe('ParallelTaskQueue', () => {
expect(queue2.toString()).toContain(' All tasks completed: false\n');
queue2.markTaskCompleted(task);
queue2.markAsCompleted(task);
expect(queue2.toString()).toContain(' All tasks completed: true\n');
});
@ -410,14 +410,14 @@ describe('ParallelTaskQueue', () => {
' - {entryPoint: entry-point-1, formatProperty: prop-0, processDts: true}\n' +
' - {entryPoint: entry-point-2, formatProperty: prop-0, processDts: true}\n');
queue.markTaskCompleted(task1);
queue.markAsCompleted(task1);
const task2 = queue.getNextTask()!;
expect(queue.toString())
.toContain(
' Unprocessed tasks (1): \n' +
' - {entryPoint: entry-point-2, formatProperty: prop-0, processDts: true}\n');
queue.markTaskCompleted(task2);
queue.markAsCompleted(task2);
processNextTask(queue);
expect(queue.toString()).toContain(' Unprocessed tasks (0): \n');
});
@ -432,14 +432,14 @@ describe('ParallelTaskQueue', () => {
' In-progress tasks (1): \n' +
' - {entryPoint: entry-point-0, formatProperty: prop-0, processDts: true}\n');
queue.markTaskCompleted(task1);
queue.markAsCompleted(task1);
const task2 = queue.getNextTask()!;
expect(queue.toString())
.toContain(
' In-progress tasks (1): \n' +
' - {entryPoint: entry-point-1, formatProperty: prop-0, processDts: true}\n');
queue.markTaskCompleted(task2);
queue.markAsCompleted(task2);
processNextTask(queue);
expect(queue.toString()).toContain(' In-progress tasks (0): \n');
});
@ -557,7 +557,7 @@ describe('ParallelTaskQueue', () => {
' - {entryPoint: entry-point-1, formatProperty: prop-0, processDts: true}');
// Complete task #1 nd start processing #2 (which is not unblocked).
queue2.markTaskCompleted(tasks2[1]);
queue2.markAsCompleted(tasks2[1]);
expect(queue2.getNextTask()).toBe(tasks2[2]);
expect(queue2.toString())
.toBe(
@ -570,8 +570,8 @@ describe('ParallelTaskQueue', () => {
' Blocked tasks (0): ');
// Complete tasks #2 and #0. All tasks are now completed.
queue2.markTaskCompleted(tasks2[2]);
queue2.markTaskCompleted(tasks2[0]);
queue2.markAsCompleted(tasks2[2]);
queue2.markAsCompleted(tasks2[0]);
expect(queue2.toString())
.toBe(
'ParallelTaskQueue\n' +

View File

@ -51,7 +51,7 @@ describe('SerialTaskQueue', () => {
*/
const processNextTask = (queue: TaskQueue): ReturnType<TaskQueue['getNextTask']> => {
const task = queue.getNextTask();
if (task !== null) queue.markTaskCompleted(task);
if (task !== null) queue.markAsCompleted(task);
return task;
};
@ -135,14 +135,14 @@ describe('SerialTaskQueue', () => {
});
});
describe('markTaskCompleted()', () => {
describe('markAsCompleted()', () => {
it('should mark a task as completed, so that the next task can be picked', () => {
const {queue} = createQueue(3);
const task = queue.getNextTask()!;
expect(() => queue.getNextTask()).toThrow();
queue.markTaskCompleted(task);
queue.markAsCompleted(task);
expect(() => queue.getNextTask()).not.toThrow();
});
@ -150,7 +150,7 @@ describe('SerialTaskQueue', () => {
const {tasks, queue} = createQueue(3);
queue.getNextTask();
expect(() => queue.markTaskCompleted(tasks[2]))
expect(() => queue.markAsCompleted(tasks[2]))
.toThrowError(
`Trying to mark task that was not in progress as completed: ` +
`{entryPoint: entry-point-2, formatProperty: prop-2, processDts: true}`);
@ -206,7 +206,7 @@ describe('SerialTaskQueue', () => {
expect(queue2.toString()).toContain(' All tasks completed: false\n');
queue2.markTaskCompleted(task);
queue2.markAsCompleted(task);
expect(queue2.toString()).toContain(' All tasks completed: true\n');
});
@ -226,14 +226,14 @@ describe('SerialTaskQueue', () => {
' - {entryPoint: entry-point-1, formatProperty: prop-1, processDts: false}\n' +
' - {entryPoint: entry-point-2, formatProperty: prop-2, processDts: true}\n');
queue.markTaskCompleted(task1);
queue.markAsCompleted(task1);
const task2 = queue.getNextTask()!;
expect(queue.toString())
.toContain(
' Unprocessed tasks (1): \n' +
' - {entryPoint: entry-point-2, formatProperty: prop-2, processDts: true}\n');
queue.markTaskCompleted(task2);
queue.markAsCompleted(task2);
processNextTask(queue);
expect(queue.toString()).toContain(' Unprocessed tasks (0): \n');
});
@ -248,14 +248,14 @@ describe('SerialTaskQueue', () => {
' In-progress tasks (1): \n' +
' - {entryPoint: entry-point-0, formatProperty: prop-0, processDts: true}');
queue.markTaskCompleted(task1);
queue.markAsCompleted(task1);
const task2 = queue.getNextTask()!;
expect(queue.toString())
.toContain(
' In-progress tasks (1): \n' +
' - {entryPoint: entry-point-1, formatProperty: prop-1, processDts: false}');
queue.markTaskCompleted(task2);
queue.markAsCompleted(task2);
processNextTask(queue);
expect(queue.toString()).toContain(' In-progress tasks (0): ');
});
@ -291,7 +291,7 @@ describe('SerialTaskQueue', () => {
' In-progress tasks (1): \n' +
' - {entryPoint: entry-point-1, formatProperty: prop-1, processDts: false}');
queue2.markTaskCompleted(task);
queue2.markAsCompleted(task);
processNextTask(queue2);
expect(queue2.toString())
.toBe(