topliceanu / schedule-drone

A reliable, fault-tolerant, persistent event scheduler for node.js
5 stars 4 forks source link

scheduler.scheduleAndStore not working as expected #7

Open raj-here opened 5 years ago

raj-here commented 5 years ago

scheduleAndStore saves the cron-job in database but it doesn't get active immediate after it's registration. Let have a scenario an user on a live project registered a cron job by hitting an api. It should be active immediate but not working as expected.

`var url = "mongodb://localhost:27017/my-test-db"; drone.setConfig( { persistence: { type: 'mongodb', connectionString: url, eventsCollection: 'schedular', options: {} } } );

scheduler = drone.daemon(); try { setTimeout(() => { scheduler.scheduleAndStore(' ', 'my-job', { task: 'sendReport', campaignId: 'abc' }, function () { console.log('job registered'); }); }, 3000); } catch (Exception) { console.log('Exception', Exception); }

scheduler.on('my-job', function (params) { if (params.task == 'sendReport') { // send campaign email // sendEmailCampaign(params.campaignId); } });`