@@ -88,11 +88,12 @@ function get( fn, order, jobType) {
88
88
, jobs = { } ;
89
89
if ( ! pending ) return fn ( null , ids ) ;
90
90
ids . forEach ( function ( id ) {
91
+ id = redis . client ( ) . stripFIFO ( id ) ; // turn zid back to regular job id
91
92
exports . get ( id , jobType , function ( err , job ) {
92
93
if ( err ) {
93
94
console . error ( err ) ;
94
95
} else {
95
- jobs [ job . id ] = job ;
96
+ jobs [ redis . client ( ) . createFIFO ( job . id ) ] = job ;
96
97
}
97
98
-- pending || fn ( null , 'desc' == order
98
99
? map ( jobs , ids ) . reverse ( )
@@ -169,6 +170,7 @@ exports.get = function( id, jobType, fn ) {
169
170
, job = new Job ;
170
171
171
172
job . id = id ;
173
+ job . zid = client . createFIFO ( id ) ;
172
174
client . hgetall ( client . getKey ( 'job:' + job . id ) , function ( err , hash ) {
173
175
if ( err ) return fn ( err ) ;
174
176
if ( ! hash ) {
@@ -224,20 +226,21 @@ exports.get = function( id, jobType, fn ) {
224
226
225
227
exports . removeBadJob = function ( id , jobType ) {
226
228
var client = redis . client ( ) ;
229
+ var zid = client . createFIFO ( id ) ;
227
230
client . multi ( )
228
231
. del ( client . getKey ( 'job:' + id + ':log' ) )
229
232
. del ( client . getKey ( 'job:' + id ) )
230
- . zrem ( client . getKey ( 'jobs:inactive' ) , id )
231
- . zrem ( client . getKey ( 'jobs:active' ) , id )
232
- . zrem ( client . getKey ( 'jobs:complete' ) , id )
233
- . zrem ( client . getKey ( 'jobs:failed' ) , id )
234
- . zrem ( client . getKey ( 'jobs:delayed' ) , id )
235
- . zrem ( client . getKey ( 'jobs' ) , id )
236
- . zrem ( client . getKey ( 'jobs:' + jobType + ':inactive' ) , id )
237
- . zrem ( client . getKey ( 'jobs:' + jobType + ':active' ) , id )
238
- . zrem ( client . getKey ( 'jobs:' + jobType + ':complete' ) , id )
239
- . zrem ( client . getKey ( 'jobs:' + jobType + ':failed' ) , id )
240
- . zrem ( client . getKey ( 'jobs:' + jobType + ':delayed' ) , id )
233
+ . zrem ( client . getKey ( 'jobs:inactive' ) , zid )
234
+ . zrem ( client . getKey ( 'jobs:active' ) , zid )
235
+ . zrem ( client . getKey ( 'jobs:complete' ) , zid )
236
+ . zrem ( client . getKey ( 'jobs:failed' ) , zid )
237
+ . zrem ( client . getKey ( 'jobs:delayed' ) , zid )
238
+ . zrem ( client . getKey ( 'jobs' ) , zid )
239
+ . zrem ( client . getKey ( 'jobs:' + jobType + ':inactive' ) , zid )
240
+ . zrem ( client . getKey ( 'jobs:' + jobType + ':active' ) , zid )
241
+ . zrem ( client . getKey ( 'jobs:' + jobType + ':complete' ) , zid )
242
+ . zrem ( client . getKey ( 'jobs:' + jobType + ':failed' ) , zid )
243
+ . zrem ( client . getKey ( 'jobs:' + jobType + ':delayed' ) , zid )
241
244
. exec ( ) ;
242
245
if ( ! exports . disableSearch ) {
243
246
getSearch ( ) . remove ( id ) ;
@@ -337,7 +340,7 @@ Job.prototype.toJSON = function() {
337
340
338
341
339
342
Job . prototype . refreshTtl = function ( ) {
340
- ( 'active' === this . state ( ) && this . _ttl > 0 ) ? this . client . zadd ( this . client . getKey ( 'jobs:' + this . state ( ) ) , Date . now ( ) + parseInt ( this . _ttl ) , this . id ) : noop ( ) ;
343
+ ( 'active' === this . state ( ) && this . _ttl > 0 ) ? this . client . zadd ( this . client . getKey ( 'jobs:' + this . state ( ) ) , Date . now ( ) + parseInt ( this . _ttl ) , this . zid ) : noop ( ) ;
341
344
} ;
342
345
343
346
@@ -625,9 +628,9 @@ Job.prototype.searchKeys = function( keys ) {
625
628
Job . prototype . remove = function ( fn ) {
626
629
var client = this . client ;
627
630
client . multi ( )
628
- . zrem ( client . getKey ( 'jobs:' + this . state ( ) ) , this . id )
629
- . zrem ( client . getKey ( 'jobs:' + this . type + ':' + this . state ( ) ) , this . id )
630
- . zrem ( client . getKey ( 'jobs' ) , this . id )
631
+ . zrem ( client . getKey ( 'jobs:' + this . state ( ) ) , this . zid )
632
+ . zrem ( client . getKey ( 'jobs:' + this . type + ':' + this . state ( ) ) , this . zid )
633
+ . zrem ( client . getKey ( 'jobs' ) , this . zid )
631
634
. del ( client . getKey ( 'job:' + this . id + ':log' ) )
632
635
. del ( client . getKey ( 'job:' + this . id ) )
633
636
. exec ( function ( err ) {
@@ -658,18 +661,18 @@ Job.prototype.state = function( state, fn ) {
658
661
var multi = client . multi ( ) ;
659
662
if ( oldState && oldState != '' && oldState != state ) {
660
663
multi
661
- . zrem ( client . getKey ( 'jobs:' + oldState ) , this . id )
662
- . zrem ( client . getKey ( 'jobs:' + this . type + ':' + oldState ) , this . id ) ;
664
+ . zrem ( client . getKey ( 'jobs:' + oldState ) , this . zid )
665
+ . zrem ( client . getKey ( 'jobs:' + this . type + ':' + oldState ) , this . zid ) ;
663
666
}
664
667
multi
665
668
. hset ( client . getKey ( 'job:' + this . id ) , 'state' , state )
666
- . zadd ( client . getKey ( 'jobs:' + state ) , this . _priority , this . id )
667
- . zadd ( client . getKey ( 'jobs:' + this . type + ':' + state ) , this . _priority , this . id ) ;
669
+ . zadd ( client . getKey ( 'jobs:' + state ) , this . _priority , this . zid )
670
+ . zadd ( client . getKey ( 'jobs:' + this . type + ':' + state ) , this . _priority , this . zid ) ;
668
671
669
672
// use promote_at as score when job moves to delayed
670
- ( 'delayed' === state ) ? multi . zadd ( client . getKey ( 'jobs:' + state ) , parseInt ( this . promote_at ) , this . id ) : noop ( ) ;
671
- ( 'active' === state && this . _ttl > 0 ) ? multi . zadd ( client . getKey ( 'jobs:' + state ) , Date . now ( ) + parseInt ( this . _ttl ) , this . id ) : noop ( ) ;
672
- ( 'active' === state && ! this . _ttl ) ? multi . zadd ( client . getKey ( 'jobs:' + state ) , this . _priority < 0 ?this . _priority :- this . _priority , this . id ) : noop ( ) ;
673
+ ( 'delayed' === state ) ? multi . zadd ( client . getKey ( 'jobs:' + state ) , parseInt ( this . promote_at ) , this . zid ) : noop ( ) ;
674
+ ( 'active' === state && this . _ttl > 0 ) ? multi . zadd ( client . getKey ( 'jobs:' + state ) , Date . now ( ) + parseInt ( this . _ttl ) , this . zid ) : noop ( ) ;
675
+ ( 'active' === state && ! this . _ttl ) ? multi . zadd ( client . getKey ( 'jobs:' + state ) , this . _priority < 0 ?this . _priority :- this . _priority , this . zid ) : noop ( ) ;
673
676
( 'inactive' === state ) ? multi . lpush ( client . getKey ( this . type + ':jobs' ) , 1 ) : noop ( ) ;
674
677
675
678
this . set ( 'updated_at' , Date . now ( ) ) ;
@@ -776,6 +779,7 @@ Job.prototype.save = function( fn ) {
776
779
// add the job for event mapping
777
780
var key = client . getKey ( 'job:' + id ) ;
778
781
self . id = id ;
782
+ self . zid = client . createFIFO ( id ) ;
779
783
self . subscribe ( function ( ) {
780
784
self . _state = self . _state || ( this . _delay ? 'delayed' : 'inactive' ) ;
781
785
if ( max ) client . hset ( key , 'max_attempts' , max ) ;
@@ -836,7 +840,7 @@ Job.prototype.update = function( fn ) {
836
840
// priority
837
841
this . set ( 'priority' , this . _priority ) ;
838
842
839
- this . client . zadd ( this . client . getKey ( 'jobs' ) , this . _priority , this . id ) ;
843
+ this . client . zadd ( this . client . getKey ( 'jobs' ) , this . _priority , this . zid ) ;
840
844
841
845
// data
842
846
this . set ( 'data' , json , function ( ) {
0 commit comments