Skip to content

Commit

Permalink
Added --failed-before filter
Browse files Browse the repository at this point in the history
  • Loading branch information
luisdalmolin committed Jul 3, 2020
1 parent 93c44a9 commit 6b274f3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ This option filters `failed_at` column. So let's say you had a bunch of jobs tha
php artisan queue:batch-retry --failed-after="today"
```

**--failed-before**

Same as the failed-after, but looking at previous dates.

```console
php artisan queue:batch-retry --failed-before="yesterday"
```

**--limit**

In case you want to run in just a specific number of jobs.
Expand Down
8 changes: 8 additions & 0 deletions src/Commands/BatchRetryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BatchRetryCommand extends Command
* @var string
*/
protected $signature = 'queue:batch-retry
{--failed-before= : Only batch retry jobs failed before some specific date}
{--failed-after= : Only batch retry jobs failed after some specific date}
{--limit= : Limit the amount of jobs to retry}
{--queue= : Only retry on a specific queue}
Expand All @@ -38,6 +39,13 @@ public function handle()
->when($this->option('queue'), function ($query) {
$query->where('queue', $this->option('queue'));
})
->when($this->option('failed-before'), function ($query) {
$query->where(
'failed_at',
'<=',
Carbon::parse($this->option('failed-before'))->format('Y-m-d H:i:s')
);
})
->when($this->option('failed-after'), function ($query) {
$query->where(
'failed_at',
Expand Down
15 changes: 15 additions & 0 deletions tests/BatchRetryCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,19 @@ public function it_can_batch_retry_limiting_by_date()
$this->assertCount(0, $newJobs->fresh()->filter());
$this->assertCount(5, $oldJobs->fresh()->filter());
}

/** @test */
public function it_can_batch_retry_limiting_by_date_before()
{
$newJobs = factory(FailedJob::class, 5)->create(['failed_at' => now()]);
$oldJobs = factory(FailedJob::class, 5)->create(['failed_at' => now()->subDays(10)]);

Artisan::call('queue:batch-retry', [
'--failed-before' => '5 days ago',
]);

$this->assertEquals(5, DB::table('jobs')->count());
$this->assertCount(5, $newJobs->fresh()->filter());
$this->assertCount(0, $oldJobs->fresh()->filter());
}
}

0 comments on commit 6b274f3

Please sign in to comment.