-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Introduce HooksService
#8962
Conversation
jest.clearAllMocks(); | ||
}); | ||
|
||
it('hooksService.inviteUsers should call userService.inviteUsers', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for adding unit tests here ✅
1 flaky test on run #5406 ↗︎
Details:
e2e/20-workflow-executions.cy.ts • 1 flaky test
Review all test suite changes for PR #8962 ↗︎ |
✅ All Cypress E2E specs passed |
@RicardoE105 @mutdmour This wrapper does not protect against renaming - there's no guarantee that whoever is renaming a method will remember to check this file or even be aware it exists. Could we add an assertion to a test instead |
@ivov If someone attempts to rename |
Let's sync later today! I'd love it if we can protect method names without adding a wrapper. |
@netroy, any thoughts here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. This makes things a lot better 👏
✅ All Cypress E2E specs passed |
private settingsRepository: SettingsRepository, | ||
private workflowRepository: WorkflowRepository, | ||
private credentialsRepository: CredentialsRepository, | ||
) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw should we move the dbCollections to this service as well? At the moment they are available in this.dbCollections
in the hooks. I would still like us to have quite flexible way to query data without needing to add a separate method for every single query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any changes to the external hooks interface should be considered a breaking change though, since we do have self-hosting customers who use external hooks.
we can definitely add the repositories here, but we should leave dbCollections as they are for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomi, the main idea is to force us to use only methods we have in the hooks service. If the repositories are also available here, we might have a case where if we change the model for that repo, we will break the hooks and not know. However, if we only use the methods we have in the hooks, we will notice here that we broke them and adjusted the method to use the new format/change. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always going to be balance between flexibility and runtime safety. I think it makes sense that certain things (like operations that change things in the DB or touch external systems like send email) have their own method to do that. But we can't think of every single use case beforehand, so thinking that we would do everything only based on the HooksService seems unrealistic. IMHO a good balance could be to have the methods here that we know we need but also expose certain repositories so we also have the flexibility. We can then put everything we know we need here, and rely on the repositories to implement the functionality for older versions that don't yet have the new methods in the HooksService. So I'd expose the repositories here as well. Then it's a mutual agreement that we don't use those unless absolutely necessary and rely on tests (in the hooks side) to make sure they work for different n8n versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as long as we don't remove dbCollections
from ExternalHooks
, I agree with @tomi.
maybe we can mark it as @deprecated
and remove it in v2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we can't think of every single use case beforehand, so thinking that we would do everything only based on the HooksService seems unrealistic. IMHO, a good balance could be to have the methods here that we know we need but also expose certain repositories so we also have the flexibility
I agree that specifying everything to be in the hooks is unrealistic, if we needed something, we would add it to the hooks service in n8n, wait for it to be release it, and then use it on the BE hooks via the hooks. So, we add functionality as we discover we need it.
We can then put everything we know we need here and rely on the repositories to implement the functionality for older versions that don't yet have the new methods in the HooksService.
For this we still have the dbCollections
we inject when loading the hooks. When people upgrade to a n8n version which include the hooks service then we use that instead. Once at instances have the hooks service we can stop using the dbCollections
altogether and as I mentioned before start adding functionality to the hooks as we need then.
Conclusion:
In any case, we need some way to keep supporting access to these repositories because we have some self-hosting users relaying on this. So will:
- Add the
dbCollections
here. - Mark the
dbCollections
in we pass as parameter in the external hooks as @deprecated
Co-authored-by: Tomi Turtiainen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
✅ All Cypress E2E specs passed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed some changes. Please let me know if you prefer to make any of these into a separate PR 🙏🏽
|
|
2 similar comments
|
|
…not-getting-invited
✅ All Cypress E2E specs passed |
* master: ci: Fix custom docker builds (no-changelog) (#9702) test: Fix e2e for projects missing instance owner (no-changelog) (#9703) ci: Refactor e2e tests to be less flaky (no-changelog) (#9695) feat(editor): Add move resources option to workflows and credentials on (#9654) fix: Introduce `HooksService` (#8962) fix(editor): Improve large data warning in input/output panel (#9671) ci(editor): Enforce type-safety in @n8n/chat builds as well (no-changelog) (#9685) fix(editor): Un-skip workflow save test (no-changelog) (#9698) refactor(core): Remove more dead code from event bus (no-changelog) (#9697) ci: Remove unused WaitTracker mocking (no-changelog) (#9694) feat: Update NPS Value Survey (#9638) refactor(core): Remove event bus channel (no-changelog) (#9663) refactor(core): Remove event bus helpers (no-changelog) (#9690) refactor(core): Merge event bus controllers and remove dead code (no-changelog) (#9688) ci: Fix e2e tests (no-changelog) (#9689) refactor(core): Use `@Licensed()` in event bus controller (no-changelog) (#9687) fix(editor): Node background for executing nodes in dark mode (#9682) fix(editor): Prevent saving already saved workflows (#9670) fix(editor): Fix node connection showing incorrect item count during … (#9684) refactor: Set up Cypress as pnpm workspace (no-changelog) (#6049)
* master: fix(editor): Add back credential type icon (no-changelog) (#9704) feat(editor): Add canvas edge toolbar hover show/hide support (no-changelog) (#9699) ci: Fix custom docker builds (no-changelog) (#9702) test: Fix e2e for projects missing instance owner (no-changelog) (#9703) ci: Refactor e2e tests to be less flaky (no-changelog) (#9695) feat(editor): Add move resources option to workflows and credentials on (#9654) fix: Introduce `HooksService` (#8962) fix(editor): Improve large data warning in input/output panel (#9671) ci(editor): Enforce type-safety in @n8n/chat builds as well (no-changelog) (#9685) fix(editor): Un-skip workflow save test (no-changelog) (#9698) refactor(core): Remove more dead code from event bus (no-changelog) (#9697) ci: Remove unused WaitTracker mocking (no-changelog) (#9694) feat: Update NPS Value Survey (#9638) refactor(core): Remove event bus channel (no-changelog) (#9663) refactor(core): Remove event bus helpers (no-changelog) (#9690)
Just noticed that the PR title here shouldn't have been |
@netroy Thanks for fixing! Not sure why I started it with that name 😅 |
Got released with |
Summary
On cloud we allow user to invite members during sign-up. This functionality was handled in part in the cloud backend hooks. In there, we were using the
UserService.inviteMembers
method. Sadly in this PR, we renamed the method toinviteUsers
and broke the functionality. To avoid this from happening again, we are introducing theHooksService
. All methods in the service must be used by the BE hooks, hence must not be removed without making sure we do not use then anymore. With this, we can avoid breaking functionally in the BE by renaming, move functionality to another service, etc.Edit:
We also added all other DB access methods to the hooks so we can slowly migrate them to rely only on the HooksService.
Related tickets and issues
https://linear.app/n8n/issue/ADO-2264/add-hooks-service-to-n8n
Review / Merge checklist
(no-changelog)
otherwise. (conventions)