question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decorator for Cron Job and select by name on execution context

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kamilmysliwieccommented, May 6, 2018

Glad to hear! 🙂 v5.0.0 will hit final release very soon

1reaction
shekohexcommented, Apr 24, 2018

Hi @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 #282

see also this pull #283 . and now we have Dynamic Module so we can write our 3rd party module, did you checked out NestRouterModule 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cron Jobs: A Comprehensive Guide - SitePoint
Learn what cron is and how to use it. This guide covers the basics of cron jobs, as well as some more advanced...
Read more >
Create and configure cron jobs - Google Cloud
Create a job · In the Google Cloud console, go to Cloud Scheduler. · Click Create job. · In the Name field, provide...
Read more >
Scheduling Tasks With Cron Jobs - Code - Envato Tuts+
This cron daemon is responsible for launching these cron jobs on schedule. The schedule resides in a configuration file named "crontab".
Read more >
Implementing Cronjob in Golang - Medium
This design enables our ETL jobs to be triggered not only by a scheduler. Scheduler has to be scheduling things, not doing them....
Read more >
How To Use node-cron to Run Scheduled Jobs in Node.js
Use Node.js and the node-cron library to schedule jobs to manage logs, back up databases, and send emails.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found