From ca172d6321787b33dc2b3a9ee38b9da57c4df59a Mon Sep 17 00:00:00 2001 From: alirezadp10 Date: Thu, 25 Jan 2024 21:14:18 +0330 Subject: [PATCH] make the time for temporarily failed jobs configurable --- src/Listeners/StoreTagsForFailedJob.php | 2 +- .../Listeners/StoreTagsForFailedTest.php | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/Listeners/StoreTagsForFailedTest.php diff --git a/src/Listeners/StoreTagsForFailedJob.php b/src/Listeners/StoreTagsForFailedJob.php index dfd0d2f6..45f7898f 100644 --- a/src/Listeners/StoreTagsForFailedJob.php +++ b/src/Listeners/StoreTagsForFailedJob.php @@ -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 ); } } diff --git a/tests/Feature/Listeners/StoreTagsForFailedTest.php b/tests/Feature/Listeners/StoreTagsForFailedTest.php new file mode 100644 index 00000000..b5ea5350 --- /dev/null +++ b/tests/Feature/Listeners/StoreTagsForFailedTest.php @@ -0,0 +1,49 @@ +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 ''; + } +}