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

make the expiration time for temporarily failed jobs configurable #1375

Merged
merged 1 commit into from
Jan 25, 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
2 changes: 1 addition & 1 deletion src/Listeners/StoreTagsForFailedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function handle(JobFailed $event)
})->all();

$this->tags->addTemporary(
2880, $event->payload->id(), $tags
config('horizon.trim.failed', 2880), $event->payload->id(), $tags
);
}
}
49 changes: 49 additions & 0 deletions tests/Feature/Listeners/StoreTagsForFailedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Laravel\Horizon\Tests\Feature\Listeners;

use Exception;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Queue\Jobs\Job;
use Laravel\Horizon\Contracts\TagRepository;
use Laravel\Horizon\Events\JobFailed;
use Laravel\Horizon\Tests\IntegrationTest;
use Mockery as m;

class StoreTagsForFailedTest extends IntegrationTest
{
protected function tearDown(): void
{
parent::tearDown();

m::close();
}

public function test_temporary_failed_job_should_be_deleted_when_the_main_job_is_deleted(): void
{
config()->set('horizon.trim.failed', 120);

$tagRepository = m::mock(TagRepository::class);

$tagRepository->shouldReceive('addTemporary')->once()->with(120, '1', ['failed:foobar'])->andReturn([]);

$this->instance(TagRepository::class, $tagRepository);

$this->app->make(Dispatcher::class)->dispatch(new JobFailed(
new Exception('job failed'), new FailedJob(), '{"id":"1","displayName":"displayName","tags":["foobar"]}'
));
}
}

class FailedJob extends Job
{
public function getJobId()
{
return '1';
}

public function getRawBody()
{
return '';
}
}
Loading