active_storage: fix blob update hooks

For some reason on Rails 6.1 the `after_update_commit` hook is properly
registered – but disappears from the record later, and in the end is
never run.

Fix it by using the general `after_commit` hook instead.
This commit is contained in:
Pierre de La Morinerie 2021-03-04 11:50:22 +00:00
parent 21980a37cc
commit 2f948f7e46
3 changed files with 71 additions and 14 deletions

View file

@ -1,8 +1,19 @@
# Request a watermark on blobs attached to a `Champs::TitreIdentiteChamp`
# after the virus scan has run.
#
# We're using a class extension here, but we could as well have a periodic
# job that watermarks relevant attachments.
#
# The `after_commit` hook is triggered, among other cases, when
# the analyzer or virus scan updates the blob metadata. When both the analyzer
# and the virus scan have run, it is now safe to start the watermarking,
# without risking to replace the picture while it is being scanned in a
# concurrent job.
module BlobTitreIdentiteWatermarkConcern
extend ActiveSupport::Concern
included do
after_update_commit :enqueue_watermark_job
after_commit :enqueue_watermark_job
end
def watermark_pending?
@ -12,7 +23,7 @@ module BlobTitreIdentiteWatermarkConcern
private
def watermark_required?
attachments.find { |attachment| attachment.record.class.name == 'Champs::TitreIdentiteChamp' }
attachments.any? { |attachment| attachment.record.class.name == 'Champs::TitreIdentiteChamp' }
end
def watermark_done?