Merge pull request #11018 from colinux/ignore-invalid-images

ETQ tech, réduit l'impact d'images invalides sur sentry
This commit is contained in:
Colin Darie 2024-11-05 16:21:37 +00:00 committed by GitHub
commit 1d2c8e15b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View file

@ -14,6 +14,10 @@ class ImageProcessorJob < ApplicationJob
# (to avoid modifying the file while it is being scanned).
retry_on FileNotScannedYetError, wait: :exponentially_longer, attempts: 10
# Usually invalid image or ImageMagick decoder blocked for this format
retry_on MiniMagick::Invalid, attempts: 3
retry_on MiniMagick::Error, attempts: 3
rescue_from ActiveStorage::PreviewError do
retry_or_discard
end
@ -82,12 +86,8 @@ class ImageProcessorJob < ApplicationJob
end
def retry_or_discard
if executions < max_attempts
if executions < 3
retry_job wait: 5.minutes
end
end
def max_attempts
3
end
end

View file

@ -21,6 +21,7 @@ module AttachmentImageProcessorConcern
return if blob.attachments.size != 1
return if blob.attachments.last.record_type == "Export"
return if !blob.content_type.in?(PROCESSABLE_TYPES)
return if blob.byte_size.zero? # some empty files may be considered as image depending on filename
ImageProcessorJob.perform_later(blob)
end