constQueue=require('bull');constvideoQueue=newQueue('video transcoding','redis://127.0.0.1:6379');constaudioQueue=newQueue('audio transcoding',{redis:{port:6379,host:'127.0.0.1',password:'foobared'},});// Specify Redis connection using objectconstimageQueue=newQueue('image transcoding');constpdfQueue=newQueue('pdf transcoding');videoQueue.process(function(job,done){// job.data contains the custom data passed when the job was created// job.id contains id of this job.// transcode video asynchronously and report progressjob.progress(42);// call done when finisheddone();// or give a error if errordone(newError('error transcoding'));// or pass it a resultdone(null,{framerate:29.5,/* etc... */});// If the job throws an unhandled exception it is also handled correctlythrownewError('some unexpected error');});audioQueue.process(function(job,done){// transcode audio asynchronously and report progressjob.progress(42);// call done when finisheddone();// or give a error if errordone(newError('error transcoding'));// or pass it a resultdone(null,{samplerate:48000,/* etc... */});// If the job throws an unhandled exception it is also handled correctlythrownewError('some unexpected error');});imageQueue.process(function(job,done){// transcode image asynchronously and report progressjob.progress(42);// call done when finisheddone();// or give a error if errordone(newError('error transcoding'));// or pass it a resultdone(null,{width:1280,height:720,/* etc... */});// If the job throws an unhandled exception it is also handled correctlythrownewError('some unexpected error');});pdfQueue.process(function(job){// Processors can also return promises instead of using the done callbackreturnpdfAsyncProcessor();});videoQueue.add({video:'http://example.com/video1.mov'});audioQueue.add({audio:'http://example.com/audio1.mp3'});imageQueue.add({image:'http://example.com/image1.tiff'});
paymentsQueue.process(function(job){// Check payments});// Repeat payment job once every day at 3:15 (am)paymentsQueue.add(paymentsData,{repeat:{cron:'15 3 * * *'}});
constQueue=require('bull');constcluster=require('cluster');constnumWorkers=8;constqueue=newQueue('test concurrent queue');if(cluster.isMaster){for(leti=0;i<numWorkers;i++){cluster.fork();}cluster.on('online',function(worker){// Let's create a few jobs for the queue workersfor(leti=0;i<500;i++){queue.add({foo:'bar'});}});cluster.on('exit',function(worker,code,signal){console.log('worker '+worker.process.pid+' died');});}else{queue.process(function(job,jobDone){console.log('Job done by worker',cluster.worker.id,job.id);jobDone();});}