E
E
efrolova19982018-12-29 16:50:41
MongoDB
efrolova1998, 2018-12-29 16:50:41

How to run cron dynamically?

I'm implementing dynamic cron launch. How to stop the old cron before starting the new one?

function test() {
    db.test.findOne({id: 1},)
        .then(res => {
        if (!res)
            return Promise.reject('Period backup not found');
       let job = cron.schedule(res.cronTime, function () {
    
            test1();
        });
            console.log(job)
    })
}
cron.schedule('* * * * *', () => 
    test();
    return true;
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question