Wednesday 25 October 2017

[Question]How would a job scheduler and Job queue go together ?

I guess this is more like an architecture/design kind of question .to demonstrate the problem let's assume we want to implement abandoned cart emails , we would like to send customers 3 emails with time windows of 1 ,2 and 3 hours.so the work flow looks like this :1-check every hour for abandoned carts2-if any,set three timers with required time windowsfor #1 i'm using node-schedule a cron-like job schedule for nodeand #2 i'm using kue a priority job queue backed by redis,//script 1 schedule.scheduleJob ('* 1 * * * *', ()=>{ let abandoned = await store.getAbandonedcheckouts (); if (abandoned.length){ abandoned.forEach(checkout=>{ var job = queue.create('abandoned', { email:checkout.email }).delay(60*60*1000).save() var job = queue.create('abandoned', { email:checkout.email }).delay( 2*60*60*1000).save() var job = queue.create('abandoned', { email:checkout.email }).delay( 3*60*60*1000).save() }) } }); with jobs being defined like: //script 2 queue.process('abandoned', function(job, done){ /* check if the checkout is still abandoned,if so sent an email */ }); Now my questions are :1-Am I using the correct tools to do this ?2-Should script #1 #2 be required by app.js script ? or should the run on their own with something like node script1.js?any better way to do this ?somehow this way seems a bit messy to meThanks in advance.

Submitted October 25, 2017 at 10:12PM by 10701220

No comments:

Post a Comment