chore(gallery): add activestorage error catching in job

This commit is contained in:
Eric Leroy-Terquem 2024-05-29 16:08:23 +02:00
parent ffc0ddc446
commit f6e54a540b
No known key found for this signature in database
GPG key ID: ECE60B4C1FA2ABB3

View file

@ -10,6 +10,10 @@ class ImageProcessorJob < ApplicationJob
# (to avoid modifying the file while it is being scanned). # (to avoid modifying the file while it is being scanned).
retry_on FileNotScannedYetError, wait: :exponentially_longer, attempts: 10 retry_on FileNotScannedYetError, wait: :exponentially_longer, attempts: 10
rescue_from ActiveStorage::PreviewError do
retry_or_discard
end
def perform(blob) def perform(blob)
return if blob.nil? return if blob.nil?
raise FileNotScannedYetError if blob.virus_scanner.pending? raise FileNotScannedYetError if blob.virus_scanner.pending?
@ -58,4 +62,14 @@ class ImageProcessorJob < ApplicationJob
end end
end end
end end
def retry_or_discard
if executions < max_attempts
retry_job wait: 5.minutes
end
end
def max_attempts
3
end
end end