diff --git a/src/Illuminate/Bus/DatabaseBatchRepository.php b/src/Illuminate/Bus/DatabaseBatchRepository.php index 3f025b06f9f2..bfad496fc352 100644 --- a/src/Illuminate/Bus/DatabaseBatchRepository.php +++ b/src/Illuminate/Bus/DatabaseBatchRepository.php @@ -9,7 +9,7 @@ use Illuminate\Database\Query\Expression; use Illuminate\Support\Str; -class DatabaseBatchRepository implements BatchRepository +class DatabaseBatchRepository implements BatchRepository, Prunable { /** * The batch factory instance. diff --git a/src/Illuminate/Bus/Prunable.php b/src/Illuminate/Bus/Prunable.php new file mode 100644 index 000000000000..5441a00dc5bf --- /dev/null +++ b/src/Illuminate/Bus/Prunable.php @@ -0,0 +1,16 @@ + 'command.queue.clear', 'QueueFailed' => 'command.queue.failed', 'QueueFlush' => 'command.queue.flush', - 'QueueFlushBatch' => 'command.queue.flush-batch', 'QueueForget' => 'command.queue.forget', 'QueueListen' => 'command.queue.listen', + 'QueuePruneBatches' => 'command.queue.prune-batches', 'QueueRestart' => 'command.queue.restart', 'QueueRetry' => 'command.queue.retry', 'QueueRetryBatch' => 'command.queue.retry-batch', @@ -679,10 +679,10 @@ protected function registerQueueFlushCommand() * * @return void */ - protected function registerQueueFlushBatchCommand() + protected function registerQueueListenCommand() { - $this->app->singleton('command.queue.flush-batch', function () { - return new FlushBatchQueueCommand; + $this->app->singleton('command.queue.listen', function ($app) { + return new QueueListenCommand($app['queue.listener']); }); } @@ -691,10 +691,10 @@ protected function registerQueueFlushBatchCommand() * * @return void */ - protected function registerQueueListenCommand() + protected function registerQueuePruneBatchesCommand() { - $this->app->singleton('command.queue.listen', function ($app) { - return new QueueListenCommand($app['queue.listener']); + $this->app->singleton('command.queue.prune-batches', function () { + return new PruneBatchesQueueCommand; }); } diff --git a/src/Illuminate/Queue/Console/FlushBatchCommand.php b/src/Illuminate/Queue/Console/PruneBatchesCommand.php similarity index 78% rename from src/Illuminate/Queue/Console/FlushBatchCommand.php rename to src/Illuminate/Queue/Console/PruneBatchesCommand.php index eaafe61908c7..d30b6fdb0e8d 100644 --- a/src/Illuminate/Queue/Console/FlushBatchCommand.php +++ b/src/Illuminate/Queue/Console/PruneBatchesCommand.php @@ -4,16 +4,17 @@ use Carbon\Carbon; use Illuminate\Bus\BatchRepository; +use Illuminate\Bus\Prunable; use Illuminate\Console\Command; -class FlushBatchCommand extends Command +class PruneBatchesCommand extends Command { /** * The console command signature. * * @var string */ - protected $signature = 'queue:flush-batch {--hours=24 : The number of hours to retain batch data}'; + protected $signature = 'queue:prune-batches {--hours=24 : The number of hours to retain batch data}'; /** * The console command description. @@ -33,7 +34,7 @@ public function handle() $repository = $this->laravel[BatchRepository::class]; - if (method_exists($repository, 'prune')) { + if ($repository instanceof Prunable) { $hours = $this->option('hours'); $before = Carbon::now()->subHours($hours); diff --git a/src/Illuminate/Support/Testing/Fakes/BatchRepositoryFake.php b/src/Illuminate/Support/Testing/Fakes/BatchRepositoryFake.php index 7c109db7b882..55681f4d5534 100644 --- a/src/Illuminate/Support/Testing/Fakes/BatchRepositoryFake.php +++ b/src/Illuminate/Support/Testing/Fakes/BatchRepositoryFake.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Closure; -use DateTimeInterface; use Illuminate\Bus\Batch; use Illuminate\Bus\BatchRepository; use Illuminate\Bus\PendingBatch; @@ -135,15 +134,4 @@ public function transaction(Closure $callback) { return $callback(); } - - /** - * Prune all of the entries older than the given date. - * - * @param DateTimeInterface $before - * @return int - */ - public function prune(DateTimeInterface $before) - { - return 0; - } }