Skip to content
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(funnel): allow pluginRequest to trigger events #2542

Merged
merged 5 commits into from
Jul 19, 2024

Conversation

QuentinRousselet
Copy link
Contributor

What does this PR do ?

This PR introduces an optional parameter "allowTriggerEvents" in KuzzleRequest to allow or not API actions to trigger events and pipes.
In the funnel if a pluginRequest holds this parameter, the request is processed as a normal request otherwise it is treated as usally without triggering events.

How should this be manually tested?

In a project using Kuzzle:
-Set up a custom controller creating a document for example
-Set up a pipe that triggers on the creation of document ('document:beforeCreate/document:afterCreate)
-Send a request to your controller without "allowTriggerEvents": the pipe shouldn't trigger
-Send a request to your controller with allowTriggerEvents:true the pipe should trigger.

Other changes

With this process the request also triggers statistic counts which it wouldn't have in the normal pluginRequest execution

@QuentinRousselet QuentinRousselet self-assigned this Jul 15, 2024
Copy link
Member

@etrousset etrousset left a comment

Choose a reason for hiding this comment

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

We should get a way to had this flag through calling internal sdk API such as this.sdk.document.create( "my_index", "my_collection", {...} , { 'allowTriggerEvent' : true}

@QuentinRousselet
Copy link
Contributor Author

We should get a way to had this flag through calling internal sdk API such as this.sdk.document.create( "my_index", "my_collection", {...} , { 'allowTriggerEvent' : true}

It is already the case, here is the code in the Iot platform with the custom controller that I used to test the feature

customCreateDocument: {
          handler: async (request: KuzzleRequest) => {
            const res = await this.sdk.document.create(
              request.getIndex(),
              'measures',
              {
                values: { zone: 'CREATED VIA CONTROLLER' },
              },
              undefined,
              { allowTriggerEvents: request.input.allowTriggerEvents },
            );
            return res;
          },
        },
        ```
        the methods on sdk.document takes an option object (here the 5th argument) in which we can set the flag 

@etrousset
Copy link
Member

We should get a way to had this flag through calling internal sdk API such as this.sdk.document.create( "my_index", "my_collection", {...} , { 'allowTriggerEvent' : true}

It is already the case, here is the code in the Iot platform with the custom controller that I used to test the feature

customCreateDocument: {
          handler: async (request: KuzzleRequest) => {
            const res = await this.sdk.document.create(
              request.getIndex(),
              'measures',
              {
                values: { zone: 'CREATED VIA CONTROLLER' },
              },
              undefined,
              { allowTriggerEvents: true }, // ici on devrait plutôt avoir ça à l'usage
            );
            return res;
          },
        },
        ```
        the methods on sdk.document takes an option object (here the 5th argument) in which we can set the flag 

doc/2/guides/develop-on-kuzzle/event-system/index.md Outdated Show resolved Hide resolved
doc/2/guides/develop-on-kuzzle/event-system/index.md Outdated Show resolved Hide resolved
doc/2/guides/develop-on-kuzzle/event-system/index.md Outdated Show resolved Hide resolved
doc/2/guides/develop-on-kuzzle/event-system/index.md Outdated Show resolved Hide resolved
lib/api/funnel.js Outdated Show resolved Hide resolved
lib/api/request/requestInput.ts Outdated Show resolved Hide resolved
lib/api/request/requestInput.ts Outdated Show resolved Hide resolved
lib/api/request/requestInput.ts Outdated Show resolved Hide resolved
lib/api/request/requestInput.ts Outdated Show resolved Hide resolved
test/api/funnel/executePluginRequest.test.js Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Jul 17, 2024

@etrousset etrousset merged commit 76a7bb9 into 2-dev Jul 19, 2024
33 checks passed
@kuzzle
Copy link
Contributor

kuzzle commented Jul 22, 2024

🎉 This PR is included in version 2.31.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kuzzle
Copy link
Contributor

kuzzle commented Jul 22, 2024

🎉 This PR is included in version 2.31.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kuzzle kuzzle added the released This issue/pull request has been released. label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @beta released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants