From f6e54a540bcaef229cb28c5bbfeb1236dbc6a1f4 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 29 May 2024 16:08:23 +0200 Subject: [PATCH] chore(gallery): add activestorage error catching in job --- app/jobs/image_processor_job.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/jobs/image_processor_job.rb b/app/jobs/image_processor_job.rb index 798ba86a1..ee914a925 100644 --- a/app/jobs/image_processor_job.rb +++ b/app/jobs/image_processor_job.rb @@ -10,6 +10,10 @@ class ImageProcessorJob < ApplicationJob # (to avoid modifying the file while it is being scanned). retry_on FileNotScannedYetError, wait: :exponentially_longer, attempts: 10 + rescue_from ActiveStorage::PreviewError do + retry_or_discard + end + def perform(blob) return if blob.nil? raise FileNotScannedYetError if blob.virus_scanner.pending? @@ -58,4 +62,14 @@ class ImageProcessorJob < ApplicationJob end end end + + def retry_or_discard + if executions < max_attempts + retry_job wait: 5.minutes + end + end + + def max_attempts + 3 + end end