refactor(ngcc): add message text to task outcomes (#36083)

This sets up the task execution to be able to report failed compiles

PR Close #36083
This commit is contained in:
Pete Bacon Darwin 2020-03-14 13:20:51 +00:00 committed by Andrew Kushnir
parent d50881a86e
commit 712f2642d5
5 changed files with 22 additions and 6 deletions

View File

@ -71,12 +71,15 @@ export interface Task extends JsonObject {
}
/** A function to be called once a task has been processed. */
export type TaskCompletedCallback = (task: Task, outcome: TaskProcessingOutcome) => void;
export type TaskCompletedCallback =
(task: Task, outcome: TaskProcessingOutcome, message: string | null) => void;
/** Represents the outcome of processing a `Task`. */
export const enum TaskProcessingOutcome {
/** Successfully processed the target format property. */
Processed,
/** Failed to process the target format. */
Failed,
}
/**

View File

@ -33,6 +33,7 @@ export interface ProcessTaskMessage extends JsonObject {
export interface TaskCompletedMessage extends JsonObject {
type: 'task-completed';
outcome: TaskProcessingOutcome;
message: string|null;
}
/** A message requesting the update of a `package.json` file. */

View File

@ -30,8 +30,9 @@ export class ClusterWorker {
throw new Error('Tried to instantiate `ClusterWorker` on the master process.');
}
this.compile =
createCompileFn((_task, outcome) => sendMessageToMaster({type: 'task-completed', outcome}));
this.compile = createCompileFn(
(_task, outcome, message) =>
sendMessageToMaster({type: 'task-completed', outcome, message}));
}
run(): Promise<void> {

View File

@ -300,7 +300,7 @@ export function mainNgcc({basePath, targetEntryPointPath,
logger.debug(` Successfully compiled ${entryPoint.name} : ${formatProperty}`);
onTaskCompleted(task, TaskProcessingOutcome.Processed);
onTaskCompleted(task, TaskProcessingOutcome.Processed, null);
};
};

View File

@ -54,15 +54,26 @@ describe('ClusterWorker', () => {
expect(createCompileFnSpy).toHaveBeenCalledWith(jasmine.any(Function));
});
it('should set up `compileFn()` to send a `task-completed` message to master', () => {
it('should set up `compileFn()` to send `task-completed` messages to master', () => {
new ClusterWorker(mockLogger, createCompileFnSpy);
const onTaskCompleted: TaskCompletedCallback = createCompileFnSpy.calls.argsFor(0)[0];
onTaskCompleted(null as any, TaskProcessingOutcome.Processed);
onTaskCompleted(null as any, TaskProcessingOutcome.Processed, null);
expect(processSendSpy).toHaveBeenCalledTimes(1);
expect(processSendSpy).toHaveBeenCalledWith({
type: 'task-completed',
outcome: TaskProcessingOutcome.Processed,
message: null
});
processSendSpy.calls.reset();
onTaskCompleted(null as any, TaskProcessingOutcome.Failed, 'error message');
expect(processSendSpy).toHaveBeenCalledTimes(1);
expect(processSendSpy).toHaveBeenCalledWith({
type: 'task-completed',
outcome: TaskProcessingOutcome.Failed,
message: 'error message',
});
});
});