Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persist my cron jobs and execute them even if my node server restarted

I have my app in node js and i want them to be executed on its scheduled time
But the problem is in between that if my server crash/stop/restart then those scheduled jobs are not persisted and are not executed.
Also, all my jobs are scheduled and executed using only single process, but i want multiple process to do the job.
I want all my jobs to be persisted and executed even if my node server restarted or better its get executed even if my server is not running.

Agenda - using mongoDB, which i don't want to use.
Node-scheduler - not able to persist cron jobs

    var ctab = require('crontab');
    ctab.load(function(err, crontab) {
      var job = crontab.create('* * * * * *');
      var jobs = crontab.jobs();
      crontab.save(function(err, crontab) {
    });
});

like image 923
Shubham Tripathi Avatar asked Apr 12 '16 08:04

Shubham Tripathi


People also ask

Do Cronjobs run automatically?

The cron reads the crontab (cron tables) for running predefined scripts. By using a specific syntax, you can configure a cron job to schedule scripts or other commands to run automatically.

How do I make sure my cron job runs?

Using Output In a Script to Show a Running Cron Job The easiest way to see if a cron job (with its crontab settings) is working is to edit an existing cron job so that it produces a visible output. You can add a line of code in your existing script to output a result when the script is run.

Are Cronjobs persistent?

Persistence Via Cron Jobs This technique involves leveraging Cron jobs to maintain persistent access to the target system by executing a reverse shell command or a web shell repeatedly on a specified schedule.


1 Answers

There is a few node packages to management and persist scheduled jobs:

  • Agenda (mongodb persistence)
  • Bree (Redis persistence)
  • Bull (Redis persistence)
  • nodejs-persistable-scheduler (MySql persistence)
like image 64
J.C. Gras Avatar answered Oct 15 '22 04:10

J.C. Gras