Skip to content

Commit 98b97aa

Browse files
authored
Merge pull request #3 from lasselehtinen/master
Added --exclude-filter
2 parents b717b5b + 6cfbdef commit 98b97aa

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ php artisan queue:failed:batch-retry --filter="PublishDocumentJob"
3535
php artisan queue:failed:batch-retry --filter="12234"
3636
```
3737

38+
**--exclude-filter**
39+
40+
This is exact same as --filter, except in reverse. It will search all the payloads and exclude those given in the parameter.
41+
42+
```console
43+
php artisan queue:failed:batch-retry --exclude-filter="PublishDocumentJob"
44+
```
45+
3846
**--filter-by-exception**
3947

4048
Same as the `--filter` option, but for the `exception` column in the `failed_jobs` table. Using this option, depending on how many records you have, could be very slow since it will have to do a full table scan to find results.

src/Commands/BatchRetryCommand.php

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class BatchRetryCommand extends Command
1919
{--limit= : Limit the amount of jobs to retry}
2020
{--queue= : Only retry on a specific queue}
2121
{--filter= : Filter by a specific string. This will be a search in the payload of the job}
22+
{--exclude-filter= : Filter by excluding a specific string. This will be a search in the payload of the job}
2223
{--filter-by-exception= : Filter by a specific string on the exception.}
2324
{--dry-run : Do a dry run of the batch retry to have an idea of the size of the batch}';
2425

@@ -57,6 +58,9 @@ public function handle()
5758
->when($this->option('filter'), function ($query) {
5859
$query->where('payload', 'like', '%'.$this->option('filter').'%');
5960
})
61+
->when($this->option('exclude-filter'), function ($query) {
62+
$query->where('payload', 'not like', '%'.$this->option('exclude-filter').'%');
63+
})
6064
->when($this->option('filter-by-exception'), function ($query) {
6165
$query->where('exception', 'like', '%'.$this->option('filter-by-exception').'%');
6266
});

tests/BatchRetryCommandTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ public function it_can_batch_retry_using_search()
9090
$this->assertNotNull($someOtherFailedJob->fresh());
9191
}
9292

93+
/** @test */
94+
public function it_can_batch_retry_using_excluded_search()
95+
{
96+
$someFailedJob = factory(FailedJob::class)->create([
97+
'payload' => ['displayName' => 'App\Jobs\SomeJob']
98+
]);
99+
$someOtherFailedJob = factory(FailedJob::class)->create([
100+
'payload' => ['displayName' => 'App\Jobs\SomeOtherJob']
101+
]);
102+
103+
Artisan::call('queue:failed:batch-retry', [
104+
'--exclude-filter' => 'SomeJob',
105+
]);
106+
107+
$this->assertEquals(1, DB::table('jobs')->count());
108+
$this->assertNotNull($someFailedJob->fresh());
109+
$this->assertNull($someOtherFailedJob->fresh());
110+
}
111+
93112
/** @test */
94113
public function it_can_batch_retry_limiting_by_date()
95114
{

0 commit comments

Comments
 (0)