madhums / node-express-mongoose-demo

A simple demo app using node and mongodb for beginners (with docker)

Home Page:https://nodejs-express-demo.fly.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Where and how would you put cron scripts?

wmh opened this issue · comments

I'm new to nodejs and like this approach to build a project. I would like to know where to put your cron scripts?

I would use something like kue. It has a lot of features and you get an admin interface to view queued jobs + you get to use redis (which happens to be good in scheduling). You could just create a folder called jobs and put scripts which you want to execute there. And a kue.js to initiate and register jobs somewhere in config/ which you can require and call in the model files (like after save or something)

So basically:

  • Your delayed job scripts in jobs/
  • Initialize kue in config/kue.js
  • Register delayed jobs in your model files by requiring config/kue and calling the required method.