Skip to content

Commit

Permalink
use hours
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 26, 2021
1 parent 76762f9 commit 6daecf4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Queue/Console/FlushFailedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FlushFailedCommand extends Command
*
* @var string
*/
protected $signature = 'queue:flush {--age= : Only clear failed jobs older than the given age in days}';
protected $signature = 'queue:flush {--hours= : The number of hours to retain failed job data}';

/**
* The name of the console command.
Expand All @@ -36,10 +36,10 @@ class FlushFailedCommand extends Command
*/
public function handle()
{
$this->laravel['queue.failer']->flush($this->option('age'));
$this->laravel['queue.failer']->flush($this->option('hours'));

if ($this->option('age')) {
$this->info("Failed jobs older than {$this->option('age')} days deleted successfully!");
if ($this->option('hours')) {
$this->info("All jobs that failed more than {$this->option('hours')} hours ago have been deleted successfully!");

return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ public function forget($id)
/**
* Flush all of the failed jobs from storage.
*
* @param int|null $age
* @param int|null $hours
* @return void
*/
public function flush($age = null)
public function flush($hours = null)
{
$this->getTable()->when($age, function ($query, $age) {
$query->where('failed_at', '<=', Date::now()->subDays($age));
$this->getTable()->when($hours, function ($query, $hours) {
$query->where('failed_at', '<=', Date::now()->subHours($hours));
})->delete();
}

Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Queue/Failed/DatabaseUuidFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public function forget($id)
/**
* Flush all of the failed jobs from storage.
*
* @param int|null $age
* @param int|null $hours
* @return void
*/
public function flush($age = null)
public function flush($hours = null)
{
$this->getTable()->when($age, function ($query, $age) {
$query->where('failed_at', '<=', Date::now()->subDays($age));
$this->getTable()->when($hours, function ($query, $hours) {
$query->where('failed_at', '<=', Date::now()->subHours($hours));
})->delete();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Queue/Failed/DynamoDbFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ public function forget($id)
/**
* Flush all of the failed jobs from storage.
*
* @param int|null $age
* @param int|null $hours
* @return void
*
* @throws \Exception
*/
public function flush($age = null)
public function flush($hours = null)
{
throw new Exception("DynamoDb failed job storage may not be flushed. Please use DynamoDb's TTL features on your expires_at attribute.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Queue/Failed/FailedJobProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function forget($id);
/**
* Flush all of the failed jobs from storage.
*
* @param int|null $age
* @param int|null $hours
* @return void
*/
public function flush($age = null);
public function flush($hours = null);
}
4 changes: 2 additions & 2 deletions src/Illuminate/Queue/Failed/NullFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public function forget($id)
/**
* Flush all of the failed jobs from storage.
*
* @param int|null $age
* @param int|null $hours
* @return void
*/
public function flush($age = null)
public function flush($hours = null)
{
//
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Queue/DatabaseFailedJobProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function testCanFlushFailedJobs()
$this->assertSame(0, $db->getConnection()->table('failed_jobs')->count());

$db->getConnection()->table('failed_jobs')->insert(['failed_at' => Date::now()->subDays(10)]);
$provider->flush(15);
$provider->flush(15 * 24);
$this->assertSame(1, $db->getConnection()->table('failed_jobs')->count());

$db->getConnection()->table('failed_jobs')->insert(['failed_at' => Date::now()->subDays(10)]);
$provider->flush(10);
$provider->flush(10 * 24);
$this->assertSame(0, $db->getConnection()->table('failed_jobs')->count());
}
}

0 comments on commit 6daecf4

Please sign in to comment.