Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs - How to set cron job to run on every 2 Sunday

Tags:

node.js

cron

Below cron job runs every Sunday 14:35:00, but I want to run the run job every 2 Sunday 14:35:00.

Is it possible to do that?

var CronJob = require('cron').CronJob;

new CronJob('0 35 14 * * 0', async function () { 

}, null, true, 'America/Los_Angeles');
like image 974
CCCC Avatar asked Oct 26 '22 15:10

CCCC


1 Answers

I didn't see any pattern for your requirement, but you can this

var CronJob = require('cron').CronJob;

var x = 1;
new CronJob('0 35 14 * * 0', async function () { 
    if (x / 2 != 1) {
        x++;
      //do somthing
    } else {
      x = 1;
    }
}, null, true, 'America/Los_Angeles');
like image 171
Mohammad Yaser Ahmadi Avatar answered Nov 07 '22 23:11

Mohammad Yaser Ahmadi