@@ -169,7 +169,7 @@ public function markJobFailed($id, $failureMessage = null) {
169
169
* @param string $taskName A task name to count
170
170
* @return int The number of pending jobs
171
171
*/
172
- public function getLength ($ taskName = null ) {
172
+ public function getLength ($ taskName = null ) : int {
173
173
$ conditions = ['completed ' => null ];
174
174
if (!empty ($ taskName )) {
175
175
$ conditions ['task ' ] = $ taskName ;
@@ -183,7 +183,7 @@ public function getLength($taskName = null) {
183
183
*
184
184
* @return array A list of task names
185
185
*/
186
- public function getTypes () {
186
+ public function getTypes () : array {
187
187
$ fields = ['task ' , 'task ' ];
188
188
$ group = ['task ' ];
189
189
@@ -195,7 +195,7 @@ public function getTypes() {
195
195
*
196
196
* @return array An array with statistics
197
197
*/
198
- public function getStats () {
198
+ public function getStats () : array {
199
199
$ fields = [
200
200
'task ' ,
201
201
'COUNT(id) AS num ' ,
@@ -215,19 +215,21 @@ public function getStats() {
215
215
* @param array $capabilities Available queue worker tasks.
216
216
* @return bool Success
217
217
*/
218
- public function cleanOldJobs ($ capabilities ) {
219
- $ conditions = [];
220
-
221
- // Generate the job specific conditions
218
+ public function cleanOldJobs (array $ capabilities ) : bool {
219
+ $ success = true ;
222
220
foreach ($ capabilities as $ task ) {
223
- list ($ plugin , $ name ) = pluginSplit ($ task ['name ' ]);
224
- $ conditions[ ' OR ' ][] = [
221
+ list (, $ name ) = pluginSplit ($ task ['name ' ]);
222
+ $ conditions = [
225
223
'task ' => $ name ,
226
224
'completed < ' => date ('Y-m-d H:i:s ' , time () - $ task ['cleanupTimeout ' ])
227
225
];
226
+ if (!$ this ->deleteAll ($ conditions , false )) {
227
+ $ success = false ;
228
+ break ;
229
+ }
228
230
}
229
231
230
- return $ this -> deleteAll ( $ conditions , false ) ;
232
+ return $ success ;
231
233
}
232
234
233
235
/**
@@ -236,19 +238,21 @@ public function cleanOldJobs($capabilities) {
236
238
* @param array $capabilities Available queue worker tasks.
237
239
* @return bool Success
238
240
*/
239
- public function cleanFailedJobs ($ capabilities ) {
240
- $ conditions = [];
241
-
242
- // Generate the job specific conditions.
241
+ public function cleanFailedJobs (array $ capabilities ) : bool {
242
+ $ success = true ;
243
243
foreach ($ capabilities as $ task ) {
244
- list ($ plugin , $ name ) = pluginSplit ($ task ['name ' ]);
245
- $ conditions[ ' OR ' ][] = [
244
+ list (, $ name ) = pluginSplit ($ task ['name ' ]);
245
+ $ conditions = [
246
246
'task ' => $ name ,
247
247
'failed_count > ' => $ task ['retries ' ]
248
248
];
249
+ if (!$ this ->deleteAll ($ conditions , false )) {
250
+ $ success = false ;
251
+ break ;
252
+ }
249
253
}
250
254
251
- return $ this -> deleteAll ( $ conditions , false ) ;
255
+ return $ success ;
252
256
}
253
257
254
258
/**
0 commit comments