Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor(core): Move ExecutionLifecycleHooks to core #13042

Merged
merged 7 commits into from
Feb 7, 2025

Conversation

netroy
Copy link
Member

@netroy netroy commented Feb 4, 2025

Summary

This is a continuation of the execution-lifecycle hooks refactor. extracted out of #12364.

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team node/improvement New feature or request labels Feb 4, 2025
Co-authored-by: Tomi Turtiainen <10324676+tomi@users.noreply.github.com>
@@ -61,7 +61,7 @@ export class WorkflowRunner {
startedAt: Date,
executionMode: WorkflowExecuteMode,
executionId: string,
hooks?: WorkflowHooks,
hooks?: ExecutionLifecycleHooks,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every call to processError passes hooks, can we make them required and remove the optional access below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to make hooks required wherever I can, but we'll still have some places where it'll be optional, until we rewrite credentials testing to stop using the execution engine.

packages/cli/src/workflow-runner.ts Outdated Show resolved Hide resolved
await expect(hooks.runHook('nodeExecuteBefore', ['testNode'])).rejects.toThrow('Hook failed');
});
});
});
Copy link
Contributor

@ivov ivov Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More ideas :)

  • if a handler fails, should continue executing remaining handlers
  • if a hook has no handlers, running the hook should not throw
  • if two handlers are added for a hook, both should be called (not overridden)

Comment on lines +47 to +49
mock<{
[K in keyof ExecutionLifecyleHookHandlers]: ExecutionLifecyleHookHandlers[K][number];
}>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or mock<ExecutionLifecyleHookHandlers>()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't get this to work

Comment on lines +102 to +107
const typedHookFunction = hookFunction as unknown as (
this: ExecutionLifecycleHooks,
...args: Params
) => Promise<void>;
await typedHookFunction.apply(this, parameters);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spent 15m but no luck :/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file needs another round of cleanup. same with the TODO on line 90

tomi
tomi previously approved these changes Feb 7, 2025
Copy link
Collaborator

@tomi tomi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link

cypress bot commented Feb 7, 2025

n8n    Run #9201

Run Properties:  status check passed Passed #9201  •  git commit d41ca832dc: 🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Project n8n
Branch Review master
Run status status check passed Passed #9201
Run duration 04m 37s
Commit git commit d41ca832dc: 🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Committer कारतोफ्फेलस्क्रिप्ट™
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 5
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 434
View all changes introduced in this branch ↗︎

Copy link
Contributor

github-actions bot commented Feb 7, 2025

✅ All Cypress E2E specs passed

Copy link
Contributor

github-actions bot commented Feb 7, 2025

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Copy link
Contributor

github-actions bot commented Feb 7, 2025

✅ All Cypress E2E specs passed

@netroy netroy merged commit d41ca83 into master Feb 7, 2025
38 checks passed
@netroy netroy deleted the move-WorkflowHooks-to-core branch February 7, 2025 17:16
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team node/improvement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants