From e6740618d6b8732265870ac24abe7d96dcccb3ce Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Tue, 13 Feb 2024 10:17:27 +0100 Subject: [PATCH] Improve error handling of ProcessAnnotatedFile job The job is now retried even if an error happens that would make it give up. If the error persists, the job does not fail and just writes a log message. --- src/Jobs/ProcessAnnotatedFile.php | 12 +++++++----- tests/Jobs/ProcessAnnotatedImageTest.php | 1 + tests/Jobs/ProcessAnnotatedVideoTest.php | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Jobs/ProcessAnnotatedFile.php b/src/Jobs/ProcessAnnotatedFile.php index 44af67c..9f383be 100644 --- a/src/Jobs/ProcessAnnotatedFile.php +++ b/src/Jobs/ProcessAnnotatedFile.php @@ -128,12 +128,12 @@ public function handle() ->onQueue($this->queue) ->delay(60); } catch (Exception $e) { - if ($this->shouldGiveUpAfterException($e)) { - $class = get_class($this->file); - Log::warning("Could not process annotated {$class} {$this->file->id}: {$e->getMessage()}", ['exception' => $e]); - } elseif ($this->shouldRetryAfterException($e)) { + if ($this->shouldRetryAfterException($e)) { // Exponential backoff for retry after 10 and then 20 minutes. $this->release($this->attempts() * 600); + } elseif ($this->shouldGiveUpAfterException($e)) { + $class = get_class($this->file); + Log::warning("Could not process annotated {$class} {$this->file->id}: {$e->getMessage()}", ['exception' => $e]); } else { $class = get_class($this->file); throw new ProcessAnnotatedFileException("Could not process annotated {$class} {$this->file->id}.", previous: $e); @@ -161,7 +161,9 @@ protected function shouldGiveUpAfterException(Exception $e): bool $giveUpError = ( // SSL certificate problem of the remote server. // See: https://curl.haxx.se/libcurl/c/libcurl-errors.html - Str::contains($message, 'cURL error 60:') + Str::contains($message, 'cURL error 60:') || + // File not found. + Str::contains($message, 'Unable to read file from location:') ); return $giveUpError; diff --git a/tests/Jobs/ProcessAnnotatedImageTest.php b/tests/Jobs/ProcessAnnotatedImageTest.php index 7676b88..2f30bc2 100644 --- a/tests/Jobs/ProcessAnnotatedImageTest.php +++ b/tests/Jobs/ProcessAnnotatedImageTest.php @@ -394,6 +394,7 @@ public function testHandleGiveUpError() $annotation = ImageAnnotationTest::create(); $job = new ProcessAnnotatedImage($annotation->image); + $job->tries = 1; $job->handle(); $prefix = fragment_uuid_path($annotation->image->uuid); $disk->assertMissing("{$prefix}/{$annotation->id}.svg"); diff --git a/tests/Jobs/ProcessAnnotatedVideoTest.php b/tests/Jobs/ProcessAnnotatedVideoTest.php index 420bc53..0107b0b 100644 --- a/tests/Jobs/ProcessAnnotatedVideoTest.php +++ b/tests/Jobs/ProcessAnnotatedVideoTest.php @@ -437,6 +437,7 @@ public function testHandleGiveUpError() $annotation = VideoAnnotationTest::create(); $job = new ProcessAnnotatedVideo($annotation->video); + $job->tries = 1; $job->handle(); $prefix = fragment_uuid_path($annotation->video->uuid); $disk->assertMissing("{$prefix}/v-{$annotation->id}.svg");