Rocket.Chat.Apps-engine icon indicating copy to clipboard operation
Rocket.Chat.Apps-engine copied to clipboard

[NEW] Add a bridge to the ITimers interface

Open kirillk77 opened this issue 3 years ago • 6 comments

What? :boat:

This pull request contains an implementation of the bridge to the ITimers interface.

Why? :thinking:

The ITimers interface is very useful to implement custom protocols, circuit breakers, throttlers, complex actions and so on.

kirillk77 avatar Aug 25 '21 21:08 kirillk77

Hey @cybem! Thank you for taking the time to make this PR :)

One thing that's not clear to me based on the implementation is how you intend to use this new bridge in the app. Can you provide an example?

I'm guessing it might have something to do with functions like setTimeout and setInterval, is that the case?

d-gubert avatar Aug 27 '21 21:08 d-gubert

Hey @cybem! Thank you for taking the time to make this PR :)

One thing that's not clear to me based on the implementation is how you intend to use this new bridge in the app. Can you provide an example?

Hello, Douglas @d-gubert!

We use it in that manner:

   private delay(ms: number) {
        const setTimeout = this.timers.call('setTimeout');
        return new Promise((resolve) => setTimeout(resolve, ms));
    }

But we can adapt source code of our app to more elegant solution of the bridge.

Thank you for your feedback!

kirillk77 avatar Aug 30 '21 11:08 kirillk77

But we can adapt source code of our app to more elegant solution of the bridge.

We're considering allowing access to the functions directly via global scope, much like how you'd have in a pure NodeJS environment. I think it would solve your use case as well, right?

Usually we create bridges for apps to access resources that are directly related to Rocket.Chat, such as data entities like messages and rooms; or features that are tightly coupled to the database, like the persistence layer or scheduler.

These functions from the timers module are provided globally by NodeJS, so we could pass them directly to the app as well.

What do you think?

d-gubert avatar Aug 31 '21 22:08 d-gubert

What do you think?

Hello Douglas @d-gubert,

Yes, sure. It would be nice.

Thank you!

kirillk77 avatar Sep 02 '21 04:09 kirillk77

I'll be closing this PR as the latest Apps-Engine has those functions available globally. Thanks for contributing the idea :)

d-gubert avatar Oct 07 '21 14:10 d-gubert

Hello, @d-gubert As you discussed with @cybem timers module was globally available at late 2021. But now looks like that module not available again. We see that timers module is imported in Apps-Engine here https://github.com/RocketChat/Rocket.Chat.Apps-engine/blob/7af3781e5170a898030328b0502e75d9c990af8d/src/server/misc/Utilities.ts#L3 But here https://github.com/RocketChat/Rocket.Chat.Apps-engine/blob/eaec68e8179255d81364c88ab68cacbd3f120c87/src/server/compiler/modules/index.ts it not used! So, looks like a regression critical for us. Can you check that? Thank you!

ankar84 avatar Aug 19 '22 08:08 ankar84