Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add command to clean batches table #35694

Merged
merged 5 commits into from Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Bus/DatabaseBatchRepository.php
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
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing slash

* @return int
*/
public function prune(DateTimeInterface $before);
}
16 changes: 8 additions & 8 deletions src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
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
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
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;
}
}