File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,29 @@ public function pruneUnfinished(DateTimeInterface $before)
277
277
return $ totalDeleted ;
278
278
}
279
279
280
+ /**
281
+ * Prune all of the cancelled entries older than the given date.
282
+ *
283
+ * @param \DateTimeInterface $before
284
+ * @return int
285
+ */
286
+ public function pruneCancelled (DateTimeInterface $ before )
287
+ {
288
+ $ query = $ this ->connection ->table ($ this ->table )
289
+ ->whereNotNull ('cancelled_at ' )
290
+ ->where ('created_at ' , '< ' , $ before ->getTimestamp ());
291
+
292
+ $ totalDeleted = 0 ;
293
+
294
+ do {
295
+ $ deleted = $ query ->take (1000 )->delete ();
296
+
297
+ $ totalDeleted += $ deleted ;
298
+ } while ($ deleted !== 0 );
299
+
300
+ return $ totalDeleted ;
301
+ }
302
+
280
303
/**
281
304
* Execute the given Closure within a storage specific transaction.
282
305
*
Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ class PruneBatchesCommand extends Command
19
19
*/
20
20
protected $ signature = 'queue:prune-batches
21
21
{--hours=24 : The number of hours to retain batch data}
22
- {--unfinished= : The number of hours to retain unfinished batch data } ' ;
22
+ {--unfinished= : The number of hours to retain unfinished batch data }
23
+ {--cancelled= : The number of hours to retain cancelled batch data } ' ;
23
24
24
25
/**
25
26
* The name of the console command.
@@ -65,5 +66,15 @@ public function handle()
65
66
66
67
$ this ->components ->info ("{$ count } unfinished entries deleted. " );
67
68
}
69
+
70
+ if ($ this ->option ('cancelled ' )) {
71
+ $ count = 0 ;
72
+
73
+ if ($ repository instanceof DatabaseBatchRepository) {
74
+ $ count = $ repository ->pruneCancelled (Carbon::now ()->subHours ($ this ->option ('cancelled ' )));
75
+ }
76
+
77
+ $ this ->components ->info ("{$ count } cancelled entries deleted. " );
78
+ }
68
79
}
69
80
}
You can’t perform that action at this time.
0 commit comments