README
npm-xvi-cron
Cron
//Add package
const Cron = require('xvi-cron');
//Create instance of the scraper
var instance = new Cron();
//test function
async function test() {
try {
console.log('ADD JOB');
instance.addJob(
'test', //name anchor
'*/2 * * * * *', //cron like
function (args) { //callback
console.log('DOING JOB');
console.log(args);
}, {
foo: 'bar' //args passed to CB
}
);
//stop and destroy JOB
setTimeout(function () {
console.log('STOP AND DESTROY JOB');
instance.stopJob('test', true);
}, 5000);
} catch (err) {
console.log(err);
}
}
test();
Will output
170918-210755 | debug.Cron | canStart = true
ADD JOB
170918-210755 | debug.Cron | addJob: test, */2 * * * * *
170918-210756 | debug.Cron | Execute job: test */2 * * * * *
DOING JOB
{ foo: 'bar' }
170918-210758 | debug.Cron | Execute job: test */2 * * * * *
DOING JOB
{ foo: 'bar' }
STOP AND DESTROY JOB
170918-210800 | debug.Cron | stopJob: test, detroy = true
170918-210800 | debug.Cron | destroyJob: test