@@ -1129,7 +1129,7 @@ Queue.prototype.multi = function() {
1129
1129
/**
1130
1130
Returns a promise that resolves to the next job in queue.
1131
1131
*/
1132
- Queue . prototype . getNextJob = function ( ) {
1132
+ Queue . prototype . getNextJob = async function ( ) {
1133
1133
if ( this . closing ) {
1134
1134
return Promise . resolve ( ) ;
1135
1135
}
@@ -1138,27 +1138,33 @@ Queue.prototype.getNextJob = function() {
1138
1138
//
1139
1139
// Waiting for new jobs to arrive
1140
1140
//
1141
- return this . bclient
1142
- . brpoplpush ( this . keys . wait , this . keys . active , this . settings . drainDelay )
1143
- . then (
1144
- jobId => {
1145
- if ( jobId ) {
1146
- return this . moveToActive ( jobId ) ;
1147
- }
1148
- } ,
1149
- err => {
1150
- // Swallow error if locally paused since we did force a disconnection
1151
- if ( ! ( this . paused && err . message === 'Connection is closed.' ) ) {
1152
- throw err ;
1153
- }
1154
- }
1141
+ try {
1142
+ const jobId = await this . bclient . brpoplpush (
1143
+ this . keys . wait ,
1144
+ this . keys . active ,
1145
+ this . settings . drainDelay
1155
1146
) ;
1147
+
1148
+ if ( jobId ) {
1149
+ return this . moveToActive ( jobId ) ;
1150
+ }
1151
+ } catch ( err ) {
1152
+ err => {
1153
+ // Swallow error if locally paused since we did force a disconnection
1154
+ if ( ! ( this . paused && err . message === 'Connection is closed.' ) ) {
1155
+ throw err ;
1156
+ }
1157
+ } ;
1158
+ }
1156
1159
} else {
1157
1160
return this . moveToActive ( ) ;
1158
1161
}
1159
1162
} ;
1160
1163
1161
- Queue . prototype . moveToActive = function ( jobId ) {
1164
+ Queue . prototype . moveToActive = async function ( jobId ) {
1165
+ // For manual retrieving jobs we need to wait for the queue to be ready.
1166
+ await this . isReady ( ) ;
1167
+
1162
1168
return scripts . moveToActive ( this , jobId ) . then ( ( [ jobData , jobId ] ) => {
1163
1169
return this . nextJobFromJobData ( jobData , jobId ) ;
1164
1170
} ) ;
0 commit comments