Skip to content

Commit 322edac

Browse files
committed
Merge pull request #750 from jojihere/master
store multiple instances of jobs in jobs id map to emit events for all
2 parents 751b2b6 + 86f9b5d commit 322edac

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/queue/events.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ exports.key = 'events';
3434
exports.callbackQueue = [];
3535

3636
exports.add = function( job, callback ) {
37-
if( job.id ) exports.jobs[ job.id ] = job;
37+
if( job.id ) {
38+
if(!exports.jobs[ job.id ])
39+
exports.jobs[ job.id ] = [];
40+
41+
exports.jobs[ job.id ].push(job);
42+
}
3843
// if (!exports.subscribed) exports.subscribe();
3944
if( !exports.subscribeStarted ) exports.subscribe();
4045
if( !exports.subscribed ) {
@@ -95,10 +100,13 @@ exports.onMessage = function( channel, msg ) {
95100
msg = JSON.parse(msg);
96101

97102
// map to Job when in-process
98-
var job = exports.jobs[ msg.id ];
99-
if( job ) {
100-
job.emit.apply(job, msg.args);
101-
if( [ 'complete', 'failed' ].indexOf(msg.event) !== -1 ) exports.remove(job);
103+
var jobs = exports.jobs[ msg.id ];
104+
if( jobs && jobs.length > 0 ) {
105+
for (var i = 0; i < jobs.length; i++) {
106+
var job = jobs[i];
107+
job.emit.apply(job, msg.args);
108+
if( [ 'complete', 'failed' ].indexOf(msg.event) !== -1 ) exports.remove(job);
109+
}
102110
}
103111
// emit args on Queues
104112
msg.args[ 0 ] = 'job ' + msg.args[ 0 ];

0 commit comments

Comments
 (0)