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:
parent
d50881a86e
commit
712f2642d5
@ -71,12 +71,15 @@ export interface Task extends JsonObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** A function to be called once a task has been processed. */
|
/** 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`. */
|
/** Represents the outcome of processing a `Task`. */
|
||||||
export const enum TaskProcessingOutcome {
|
export const enum TaskProcessingOutcome {
|
||||||
/** Successfully processed the target format property. */
|
/** Successfully processed the target format property. */
|
||||||
Processed,
|
Processed,
|
||||||
|
/** Failed to process the target format. */
|
||||||
|
Failed,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,6 +33,7 @@ export interface ProcessTaskMessage extends JsonObject {
|
|||||||
export interface TaskCompletedMessage extends JsonObject {
|
export interface TaskCompletedMessage extends JsonObject {
|
||||||
type: 'task-completed';
|
type: 'task-completed';
|
||||||
outcome: TaskProcessingOutcome;
|
outcome: TaskProcessingOutcome;
|
||||||
|
message: string|null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A message requesting the update of a `package.json` file. */
|
/** A message requesting the update of a `package.json` file. */
|
||||||
|
@ -30,8 +30,9 @@ export class ClusterWorker {
|
|||||||
throw new Error('Tried to instantiate `ClusterWorker` on the master process.');
|
throw new Error('Tried to instantiate `ClusterWorker` on the master process.');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.compile =
|
this.compile = createCompileFn(
|
||||||
createCompileFn((_task, outcome) => sendMessageToMaster({type: 'task-completed', outcome}));
|
(_task, outcome, message) =>
|
||||||
|
sendMessageToMaster({type: 'task-completed', outcome, message}));
|
||||||
}
|
}
|
||||||
|
|
||||||
run(): Promise<void> {
|
run(): Promise<void> {
|
||||||
|
@ -300,7 +300,7 @@ export function mainNgcc({basePath, targetEntryPointPath,
|
|||||||
|
|
||||||
logger.debug(` Successfully compiled ${entryPoint.name} : ${formatProperty}`);
|
logger.debug(` Successfully compiled ${entryPoint.name} : ${formatProperty}`);
|
||||||
|
|
||||||
onTaskCompleted(task, TaskProcessingOutcome.Processed);
|
onTaskCompleted(task, TaskProcessingOutcome.Processed, null);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,15 +54,26 @@ describe('ClusterWorker', () => {
|
|||||||
expect(createCompileFnSpy).toHaveBeenCalledWith(jasmine.any(Function));
|
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);
|
new ClusterWorker(mockLogger, createCompileFnSpy);
|
||||||
const onTaskCompleted: TaskCompletedCallback = createCompileFnSpy.calls.argsFor(0)[0];
|
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).toHaveBeenCalledTimes(1);
|
||||||
expect(processSendSpy).toHaveBeenCalledWith({
|
expect(processSendSpy).toHaveBeenCalledWith({
|
||||||
type: 'task-completed',
|
type: 'task-completed',
|
||||||
outcome: TaskProcessingOutcome.Processed,
|
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',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user