profile
viewpoint

Ask questionsHow to kill a scheduled cron job ?

I'm curious if I have a rest API that creates and schedules a cron job.

How could I cancel this cron job at a future point? Considering the reference to the job is now out of scope when I want to cancel it.

` I can start it but I can't end it..

    var cronJob = CRON.job(frequency, function()
     {        

            updateFeedbackJob()
            .then(result =>
             {
                    printMessage("updateFeedbackJob()-> finished");
            })
             .catch(err =>
            {
                   printMessage("updateFeedbackJob()-> failed");
                    printObject(err);
            });
    });
    cronJob.start();

`

kelektiv/node-cron

Answer questions alan345

@kamleshkarwande You get the reference to the job in two ways. Either by setting a variable when instantiating var a = new Job() and then calling a.stop() via a closure or something else OR by not using an arrow function for the onTick in which case the scope of the function should be the job.

Hope that helps.

How can we save a in the database. So we can do some action on this job later?

useful!

Related questions

Something went wrong. cron reached maximum iterations hot 1
source:https://uonfu.com/
Github User Rank List