mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
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:
parent
77644860c0
commit
ebf17e1827
|
@ -613,7 +613,7 @@ export class ActiveWorkflowRunner {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return poll function which gets the global functions from n8n-core
|
* 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(
|
getExecutePollFunctions(
|
||||||
|
@ -630,19 +630,38 @@ export class ActiveWorkflowRunner {
|
||||||
mode,
|
mode,
|
||||||
activation,
|
activation,
|
||||||
);
|
);
|
||||||
// eslint-disable-next-line no-underscore-dangle
|
returnFunctions.__emit = (
|
||||||
returnFunctions.__emit = async (
|
data: INodeExecutionData[][],
|
||||||
data: INodeExecutionData[][] | ExecutionError,
|
responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>,
|
||||||
): Promise<void> => {
|
donePromise?: IDeferredPromise<IRun | undefined>,
|
||||||
if (data instanceof Error) {
|
): void => {
|
||||||
await createErrorExecution(data, node, workflowData, workflow, mode);
|
|
||||||
this.executeErrorWorkflow(data, workflowData, mode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||||
Logger.debug(`Received event to trigger execution for workflow "${workflow.name}"`);
|
Logger.debug(`Received event to trigger execution for workflow "${workflow.name}"`);
|
||||||
WorkflowHelpers.saveStaticData(workflow);
|
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;
|
return returnFunctions;
|
||||||
};
|
};
|
||||||
|
|
|
@ -160,7 +160,6 @@ export class ActiveWorkflows {
|
||||||
const pollResponse = await workflow.runPoll(node, pollFunctions);
|
const pollResponse = await workflow.runPoll(node, pollFunctions);
|
||||||
|
|
||||||
if (pollResponse !== null) {
|
if (pollResponse !== null) {
|
||||||
// eslint-disable-next-line no-underscore-dangle
|
|
||||||
pollFunctions.__emit(pollResponse);
|
pollFunctions.__emit(pollResponse);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -170,8 +169,7 @@ export class ActiveWorkflows {
|
||||||
if (testingTrigger) {
|
if (testingTrigger) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-underscore-dangle
|
pollFunctions.__emitError(error);
|
||||||
pollFunctions.__emit(error);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1874,7 +1874,12 @@ export function getExecutePollFunctions(
|
||||||
return ((workflow: Workflow, node: INode) => {
|
return ((workflow: Workflow, node: INode) => {
|
||||||
return {
|
return {
|
||||||
__emit: (data: INodeExecutionData[][]): void => {
|
__emit: (data: INodeExecutionData[][]): void => {
|
||||||
throw new Error('Overwrite NodeExecuteFunctions.getExecutePullFunctions.__emit function!');
|
throw new Error('Overwrite NodeExecuteFunctions.getExecutePollFunctions.__emit function!');
|
||||||
|
},
|
||||||
|
__emitError(error: Error) {
|
||||||
|
throw new Error(
|
||||||
|
'Overwrite NodeExecuteFunctions.getExecutePollFunctions.__emitError function!',
|
||||||
|
);
|
||||||
},
|
},
|
||||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
|
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
|
||||||
return getCredentials(workflow, node, type, additionalData, mode);
|
return getCredentials(workflow, node, type, additionalData, mode);
|
||||||
|
|
|
@ -720,7 +720,12 @@ export interface IHookFunctions {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPollFunctions {
|
export interface IPollFunctions {
|
||||||
__emit(data: INodeExecutionData[][] | NodeApiError): void;
|
__emit(
|
||||||
|
data: INodeExecutionData[][],
|
||||||
|
responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>,
|
||||||
|
donePromise?: IDeferredPromise<IRun>,
|
||||||
|
): void;
|
||||||
|
__emitError(error: Error, responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>): void;
|
||||||
getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;
|
getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;
|
||||||
getMode(): WorkflowExecuteMode;
|
getMode(): WorkflowExecuteMode;
|
||||||
getActivationMode(): WorkflowActivateMode;
|
getActivationMode(): WorkflowActivateMode;
|
||||||
|
|
Loading…
Reference in a new issue