Skip to content

Commit

Permalink
make the time for temporarily failed jobs configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezadp10 committed Jan 25, 2024
1 parent 5de2d42 commit ca172d6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
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 '';
}
}

0 comments on commit ca172d6

Please sign in to comment.