class Alchemy::Dragonfly::S3::CreatePictureThumb

Public Class Methods

call(variant, signature, uid) click to toggle source
# File lib/alchemy/dragonfly/s3/create_picture_thumb.rb, line 7
def self.call(variant, signature, uid)
  # create the thumb before uploading
  # to prevent db race conditions
  thumb = variant.picture.thumbs.create!(
    picture: variant.picture,
    signature: signature,
    uid: uid,
  )
  begin
    # fetch and process the image
    image = variant.image
    # upload the processed image
    image.store(path: uid)
  rescue RuntimeError, Excon::Error => e
    Rails.logger.warn(e)
    # destroy the thumb if processing or upload fails
    thumb.destroy
  end
end