Sha256: 5d9446410b3297c94f3acf9e01d59b7bacad791b5742b717004e32a798217f57
Contents?: true
Size: 1.5 KB
Versions: 12
Compression:
Stored size: 1.5 KB
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.to_s.sub(/(\.[^.]*)$/, '-resized\1'), content_type: blob.content_type ) tmp.close puts "\n\nSAVED IMAGE\n\n" begin if params[:backup_action].present? record.class.find_by(params[:query]).__send__(params[:backup_action].to_sym) end rescue puts "BACKUP ACTION FAILED" puts $!.message puts $!.backtrace end begin puts "\n\n PURGING BLOB \n\n" puts "blob exists? #{blob = ActiveStorage::Blob.find_by(id: blob.id).present?}" blob.purge if blob.present? puts "\n\n FINISHED PURGING BLOB \n\n" rescue end else raise ActiveRecord::RecordNotFound end return true rescue "ERROR RESIZING IMAGE" puts $!.message puts $!.backtrace.first(25) return false end end end end
Version data entries
12 entries across 12 versions & 1 rubygems