Generate all preview for assets at same time

This commit is contained in:
aignatov-bio 2019-10-10 14:17:02 +02:00
parent e68b8f55c2
commit 9d59d56818
2 changed files with 9 additions and 5 deletions

View file

@ -30,7 +30,7 @@ module ActiveStorage
return true if preview_exists
unless processing
ActiveStorage::PreviewJob.perform_later(@blob.id, params[:variation_key])
ActiveStorage::PreviewJob.perform_later(@blob.id)
@blob.attachments.take.record.update(file_processing: true)
end

View file

@ -14,12 +14,16 @@ class ActiveStorage::PreviewJob < ActiveStorage::BaseJob
retry_on ActiveStorage::IntegrityError, attempts: 3, wait: :exponentially_longer
def perform(blob_id, variation_key)
def perform(blob_id)
blob = ActiveStorage::Blob.find(blob_id)
preview = blob.representation(variation_key).processed
blob.attachments.take.record.update(file_processing: false)
preview = blob.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT).processed
Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \
"Transformations applied: #{preview.variation.transformations}"
preview = blob.representation(resize_to_limit: Constants::LARGE_PIC_FORMAT).processed
Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \
"Transformations applied: #{preview.variation.transformations}"
blob.attachments.take.record.update(file_processing: false)
end
end