Sha256: 0c934371db1b749a7c02042304e9d5d02a004815acb10a658989d25f0c7a42c0

Contents?: true

Size: 959 Bytes

Versions: 1

Compression:

Stored size: 959 Bytes

Contents

module BetterRecord
  class ResizeBlobImageJob < ApplicationJob
    queue_as :default

    def perform(**params)
      begin
        if record = params[:model].constantize.find_by(params[:query].deep_symbolize_keys)
          blob = record.__send__(params[:attachment].to_sym).blob
          tmp = Tempfile.new
          tmp.binmode
          tmp.write(blob.service.download(blob.variant(params[:options]).processed.key))
          tmp.flush
          tmp.rewind
          record.__send__(params[:attachment]).attach(
            io: tmp,
            filename: blob.filename,
            content_type: blob.content_type
          )
          begin
            blob.purge_later
          rescue
          end
          params[:backup_action].present? && record.__send__(params[:backup_action].to_sym)
        end
        true
      rescue
        p $!.to_s
        p $!.message
        p $!.backtrace.first(25)
        return false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
better_record-0.15.1 app/jobs/better_record/resize_blob_image_job.rb