Skip to content

Commit

Permalink
Merge pull request #150 from biigle/patch-1
Browse files Browse the repository at this point in the history
Improve error handling of ProcessAnnotatedFile job
  • Loading branch information
mzur authored Feb 13, 2024
2 parents 7cbb5a0 + e674061 commit 9456bfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Jobs/ProcessAnnotatedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/Jobs/ProcessAnnotatedImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions tests/Jobs/ProcessAnnotatedVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 9456bfb

Please sign in to comment.