refactor: make IPollFunctions emit consistent with trigger emit (#4201)

* refactor: make IPollFunctions emit consistent with trigger emit

* refactor: re-add underscores to poll emits

* chore: update emit override message
This commit is contained in:
Valya
2022-11-08 13:29:20 +00:00
committed by GitHub
parent 77644860c0
commit ebf17e1827
4 changed files with 43 additions and 16 deletions

View File

@@ -613,7 +613,7 @@ export class ActiveWorkflowRunner {
/**
* Return poll function which gets the global functions from n8n-core
* and overwrites the __emit to be able to start it in subprocess
* and overwrites the emit to be able to start it in subprocess
*
*/
getExecutePollFunctions(
@@ -630,19 +630,38 @@ export class ActiveWorkflowRunner {
mode,
activation,
);
// eslint-disable-next-line no-underscore-dangle
returnFunctions.__emit = async (
data: INodeExecutionData[][] | ExecutionError,
): Promise<void> => {
if (data instanceof Error) {
await createErrorExecution(data, node, workflowData, workflow, mode);
this.executeErrorWorkflow(data, workflowData, mode);
return;
}
returnFunctions.__emit = (
data: INodeExecutionData[][],
responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>,
donePromise?: IDeferredPromise<IRun | undefined>,
): void => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Logger.debug(`Received event to trigger execution for workflow "${workflow.name}"`);
WorkflowHelpers.saveStaticData(workflow);
this.runWorkflow(workflowData, node, data, additionalData, mode);
const executePromise = this.runWorkflow(
workflowData,
node,
data,
additionalData,
mode,
responsePromise,
);
if (donePromise) {
executePromise.then((executionId) => {
activeExecutions
.getPostExecutePromise(executionId)
.then(donePromise.resolve)
.catch(donePromise.reject);
});
} else {
executePromise.catch(console.error);
}
};
returnFunctions.__emitError = async (error: ExecutionError): Promise<void> => {
await createErrorExecution(error, node, workflowData, workflow, mode);
this.executeErrorWorkflow(error, workflowData, mode);
};
return returnFunctions;
};