Skip to content

Commit

Permalink
Change command signature and add new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dmason30 committed Dec 23, 2020
1 parent 910fad8 commit 8dc4425
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Bus/DatabaseBatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Bus/Prunable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Illuminate\Bus;

use DateTimeInterface;

interface Prunable
{
/**
* Prune all of the entries older than the given date.
*
* @param DateTimeInterface $before
* @return int
*/
public function prune(DateTimeInterface $before);
}
16 changes: 8 additions & 8 deletions src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
use Illuminate\Queue\Console\BatchesTableCommand;
use Illuminate\Queue\Console\ClearCommand as QueueClearCommand;
use Illuminate\Queue\Console\FailedTableCommand;
use Illuminate\Queue\Console\FlushBatchCommand as FlushBatchQueueCommand;
use Illuminate\Queue\Console\FlushFailedCommand as FlushFailedQueueCommand;
use Illuminate\Queue\Console\ForgetFailedCommand as ForgetFailedQueueCommand;
use Illuminate\Queue\Console\ListenCommand as QueueListenCommand;
use Illuminate\Queue\Console\ListFailedCommand as ListFailedQueueCommand;
use Illuminate\Queue\Console\PruneBatchesCommand as PruneBatchesQueueCommand;
use Illuminate\Queue\Console\RestartCommand as QueueRestartCommand;
use Illuminate\Queue\Console\RetryBatchCommand as QueueRetryBatchCommand;
use Illuminate\Queue\Console\RetryCommand as QueueRetryCommand;
Expand Down Expand Up @@ -106,9 +106,9 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid
'QueueClear' => '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',
Expand Down Expand Up @@ -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']);
});
}

Expand All @@ -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;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions src/Illuminate/Support/Testing/Fakes/BatchRepositoryFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Carbon\CarbonImmutable;
use Closure;
use DateTimeInterface;
use Illuminate\Bus\Batch;
use Illuminate\Bus\BatchRepository;
use Illuminate\Bus\PendingBatch;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 8dc4425

Please sign in to comment.