@@ -24,20 +24,9 @@ function datePlus(date, s) {
2424 return ( new Date ( delayDate ) ) . toISOString ( )
2525}
2626
27- module . exports = function ( mongoDbClient , name , opts , callback ) {
28- if ( ! callback ) {
29- callback = opts
30- opts = { }
31- }
32-
27+ module . exports = function ( mongoDbClient , name , opts ) {
3328 var queue = new Queue ( mongoDbClient , name , opts )
34- queue . col . ensureIndex ( { visible : 1 } , function ( err ) {
35- if ( err ) return callback ( err )
36- queue . col . ensureIndex ( { ack : 1 } , { unique : true , sparse : true } , function ( err ) {
37- if ( err ) return callback ( err )
38- callback ( null , queue )
39- } )
40- } )
29+ return queue
4130}
4231
4332// the Queue object itself
@@ -56,6 +45,18 @@ function Queue(mongoDbClient, name, opts) {
5645 this . delay = opts . delay || 0
5746}
5847
48+ Queue . prototype . ensureIndexes = function ( callback ) {
49+ var self = this
50+
51+ self . col . ensureIndex ( { visible : 1 } , function ( err ) {
52+ if ( err ) return callback ( err )
53+ self . col . ensureIndex ( { ack : 1 } , { unique : true , sparse : true } , function ( err ) {
54+ if ( err ) return callback ( err )
55+ callback ( )
56+ } )
57+ } )
58+ }
59+
5960Queue . prototype . add = function ( payload , callback ) {
6061 var self = this
6162 var aDate = date ( )
0 commit comments