Decorator for Cron Job and select by name on execution context
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Resuming my case of use: I have a simple controller that GET /redirects
, POST /redirects
and POST /redirects/update
.
This last one fetch an external URL and add to my database a list of redirects. Then, with my simple structure, I added a new decorator that I created.
@Post('/update')
@Cron('*/5 * * * * *')
update() {}
This Cron function is added to a list and after my app.listen
I init and invoke the method update
(or whatever I add the decorator).
The problem is, to call this update
, I can do: this.app.select(RedirectsModule).get(RedirectsController).update();
, but I can’t run this by string name, only the component.
Expected behavior
What I need is that select
and get
accepts string, not the Module and Controller.
A workaround I found is to create an array like:
[
{ name: 'FooModule', module: FooModule },
{ name: 'BarModule', module: BarModule }
]
and search the .module
based on .name
. But I don’t think it’s the best to use.
Anyway, if anybody has a batter solution to add my “cron jobs”, I would appreciate.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Glad to hear! 🙂
v5.0.0
will hit final release very soonHi @eliasjnior Did you see https://github.com/OptimalBits/bull ? it’s The fastest, most reliable, Redis-based queue for Nodejs. as said
it also supports Scheduled and repeat jobs according to a cron specification. so I think it will be suited here. in fact, @fwoelffel created a Dynamic Module around it. nest-bull, so it can be used in nest-ish way, thanks Frédéric 😄 .
So back to the
Monkey Patching
😂 that you did with nest container. imo, it’s very bad idea to get direct access to the container, as it was my idea at first 😄 see here #282see also this pull #283 . and now we have
Dynamic Module
so we can write our 3rd party module, did you checked outNestRouterModule
it’s a very good, simple example of how you could make your own dynamic modules that could be configured and change behavior as this this configuration .Regards.