Thursday, February 17, 2022

[SOLVED] Where are these Node generated CronJobs stored?

Issue

I have created CronJobs using the following code using cron, however I can't find them to destroy them. On Debian BullsEye, I have checked /etc/crontab, /etc/cron.d, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly and there isn't anything there.

This processes is run under www-data

        new cronjob('* ' + sMarr[i] + ' ' + sHarr[i] + ' * * *', function(x) {
      
          shell.exec('ffmpeg -hide_banner -loglevel warning -i '+iUarr[x]+' -c:a aac -t 00:'+dMarr[x]+':'+dSarr[x]+' -f hls /mnt/streamlinks/'+outputName+'.m3u8&', {async:true});
        }.bind(null, i), null,  true, 'Europe/London').start();
        console.log("made cron job");
      }catch{
        console.log("Error creating cronjob");  
      }

Thanks in advance.


Solution

These cron jobs are created in memory, they are not created at the system level. This allows the module to work on different OSes (e.g. Windows).

When you create a job you can hold a reference to it and then stop it any time using job.stop().

const CronJob = require('cron').CronJob;
const job = new CronJob('* * * * * *', function() {
    console.log('Sample cron job...');
}, null, false);

// Start the cron job...
job.start();

setTimeout(() => {
    console.log("Stopping cron job..");
    // Kill the cron job
    job.stop();
}, 10000)


Answered By - Terry Lennox
Answer Checked By - Timothy Miller (WPSolving Admin)