fix(cli): Fix issue with n8n crashing when error in poll method (#4008)

* 🐛 Fix issue with n8n crashing when error in poll method

* Remove unnecessary imports and add async property

* Remove unnecessary imports

*  Move createErrorExecution to genericHelper

*  Improvements

Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
Ricardo Espinoza
2022-09-15 16:16:54 -04:00
committed by GitHub
parent 07672cce7d
commit 6c41b29ad2
4 changed files with 126 additions and 11 deletions

View File

@@ -163,24 +163,35 @@ export class ActiveWorkflows {
// Get all the trigger times
const cronTimes = (pollTimes.item || []).map(toCronExpression);
// The trigger function to execute when the cron-time got reached
const executeTrigger = async () => {
const executeTrigger = async (testingTrigger = false) => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Logger.debug(`Polling trigger initiated for workflow "${workflow.name}"`, {
workflowName: workflow.name,
workflowId: workflow.id,
});
const pollResponse = await workflow.runPoll(node, pollFunctions);
if (pollResponse !== null) {
// eslint-disable-next-line no-underscore-dangle
pollFunctions.__emit(pollResponse);
try {
const pollResponse = await workflow.runPoll(node, pollFunctions);
if (pollResponse !== null) {
// eslint-disable-next-line no-underscore-dangle
pollFunctions.__emit(pollResponse);
}
} catch (error) {
// If the poll function failes in the first activation
// throw the error back so we let the user know there is
// an issue with the trigger.
if (testingTrigger) {
throw error;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-underscore-dangle
pollFunctions.__emit(error);
}
};
// Execute the trigger directly to be able to know if it works
await executeTrigger();
await executeTrigger(true);
const timezone = pollFunctions.getTimezone();