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

Added --exclude-filter #3

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ php artisan queue:failed:batch-retry --filter="PublishDocumentJob"
php artisan queue:failed:batch-retry --filter="12234"
```

**--exclude-filter**

This is exact same as --filter, except in reverse. It will search all the payloads and exclude those given in the parameter.

```console
php artisan queue:failed:batch-retry --exclude-filter="PublishDocumentJob"
```

**--filter-by-exception**

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.
Expand Down
4 changes: 4 additions & 0 deletions src/Commands/BatchRetryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class BatchRetryCommand extends Command
{--limit= : Limit the amount of jobs to retry}
{--queue= : Only retry on a specific queue}
{--filter= : Filter by a specific string. This will be a search in the payload of the job}
{--exclude-filter= : Filter by excluding a specific string. This will be a search in the payload of the job}
{--filter-by-exception= : Filter by a specific string on the exception.}
{--dry-run : Do a dry run of the batch retry to have an idea of the size of the batch}';

Expand Down Expand Up @@ -57,6 +58,9 @@ public function handle()
->when($this->option('filter'), function ($query) {
$query->where('payload', 'like', '%'.$this->option('filter').'%');
})
->when($this->option('exclude-filter'), function ($query) {
$query->where('payload', 'not like', '%'.$this->option('exclude-filter').'%');
})
->when($this->option('filter-by-exception'), function ($query) {
$query->where('exception', 'like', '%'.$this->option('filter-by-exception').'%');
});
Expand Down
19 changes: 19 additions & 0 deletions tests/BatchRetryCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ public function it_can_batch_retry_using_search()
$this->assertNotNull($someOtherFailedJob->fresh());
}

/** @test */
public function it_can_batch_retry_using_excluded_search()
{
$someFailedJob = factory(FailedJob::class)->create([
'payload' => ['displayName' => 'App\Jobs\SomeJob']
]);
$someOtherFailedJob = factory(FailedJob::class)->create([
'payload' => ['displayName' => 'App\Jobs\SomeOtherJob']
]);

Artisan::call('queue:failed:batch-retry', [
'--exclude-filter' => 'SomeJob',
]);

$this->assertEquals(1, DB::table('jobs')->count());
$this->assertNotNull($someFailedJob->fresh());
$this->assertNull($someOtherFailedJob->fresh());
}

/** @test */
public function it_can_batch_retry_limiting_by_date()
{
Expand Down
Loading