-
Notifications
You must be signed in to change notification settings - Fork 123
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
Events overhaul: loose coupling + plugin pipe timeout removal #1613
Conversation
Codecov Report
@@ Coverage Diff @@
## 2-dev #1613 +/- ##
==========================================
+ Coverage 93.31% 93.34% +0.03%
==========================================
Files 104 105 +1
Lines 7060 7082 +22
==========================================
+ Hits 6588 6611 +23
+ Misses 472 471 -1
Continue to review full report at Codecov.
|
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.
👍
(Also, I just noticed that the GatewayTimeoutError
is not used anymore)
About the |
@Aschen > I just added a commit, making Use cases: logs, statistics... and cluster synchronization. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
# [2.2.0](https://github.com/kuzzleio/kuzzle/releases/tag/2.2.0) (2020-05-15) #### Bug fixes - [ [#1626](#1626) ] Returns a token expired error when using expired jwt ([Aschen](https://github.com/Aschen)) - [ [#1623](#1623) ] Fix refresh propagation for document:delete ([Aschen](https://github.com/Aschen)) - [ [#1611](#1611) ] Create user before credentials ([benoitvidis](https://github.com/benoitvidis)) - [ [#1596](#1596) ] Keep the number of opened scroll contexts in check ([scottinet](https://github.com/scottinet)) #### New features - [ [#1614](#1614) ] Add bulk:deleteByQuery ([Aschen](https://github.com/Aschen)) #### Enhancements - [ [#1613](#1613) ] Events overhaul: loose coupling + plugin pipe timeout removal ([scottinet](https://github.com/scottinet)) - [ [#1617](#1617) ] Allows inter-plugins method calls with side-effect ([Aschen](https://github.com/Aschen)) - [ [#1618](#1618) ] Add user ID in forbidden error log ([Aschen](https://github.com/Aschen)) - [ [#1599](#1599) ] Prevent user overriding with admin:loadSecurities ([Aschen](https://github.com/Aschen)) - [ [#1606](#1606) ] Lighter and faster MQTT server ([scottinet](https://github.com/scottinet)) - [ [#1598](#1598) ] Add token hash in API key ([Aschen](https://github.com/Aschen)) - [ [#1602](#1602) ] Automatically index new fields after collection:update ([Yoann-Abbes](https://github.com/Yoann-Abbes)) ---
…1631) # Description This is an emergency patch, fixing a behavior broken by #1613 Plugins can attach either functions or function names to pipe events. When using function names, plugin developpers have no way of controlling the context used to invoke their functions, and Kuzzle expects the function to exist within the plugin main object (this is verified with assertions when plugins are loaded by Kuzzle). With Kuzzle 2.2.0, plugin pipes defined using function names are invoked with an undefined context, breaking existing implementations. This PR fixes that by binding the plugin pipe function to its object of origin, when loading the plugin. This is only applied to plugin pipes defined with function names: when using functions, plugin developpers are responsible of the function's context, as Kuzzle has no way of knowing in what object the function belongs. # How to test Load a plugin with a pipe function declared using a function name, and use `this` in the function. Example: ```js 'use strict'; class Foo { constructor() { this.foo = 'bar'; } async init (config, context) { this.config = config; this.context = context; this.pipes = { 'server:beforeNow': '_lol' }; } async _lol (rq) { console.log('============= LOL: ', this.foo); return rq; } } module.exports = Foo; ``` Without this fix, this fails with a `PluginImplementationError` stating that the `foo` property cannot be read from `undefined`. With the fix, this pipe runs as expected. # Other changes * Simplify unit tests a bit
Description
This PR changes how events are handled by Kuzzle's core component:
KuzzleEventEmitter
object, localized in the newcore/events
directoryask
:Pipes listenable by core functions and the new ask events are meant to loosely couple Kuzzle objects: instead of invoking objects directly (and sometimes manipulate their properties from the outside), objects will now be able to submit side-effect to all listening core functions without knowing which ones.
And they will be able to request information without having any knowledge about what object will ultimately answer, or from where the information will come from.
In other words, this PR aims at restoring the principle of single responsibility to objects, freeing them of knowing what side-effect should be applied to what object.
This also introduces modularity, as we'll now be able to replace (or deactivate) parts of the code with ease.
Other changes
Optimizations