# Call with DelayedJob.new.process_asset_images(...) # Run jobs locally with "rake jobs:work" module Effective class DelayedJob def process_asset(obj) if obj.kind_of?(Effective::Asset) asset = obj else asset = Effective::Asset.where(:id => (obj.to_i rescue 0)).first end if asset.present? && !asset.processed? && asset.upload_file.present? && asset.upload_file != 'placeholder' puts "Processing asset ##{asset.id} from #{asset.upload_file}." if asset.data.respond_to?(:aws_acl) asset.data.aws_acl = asset.aws_acl asset.data.versions.each { |_, data| data.aws_acl = asset.aws_acl } end if asset.upload_file.include?(Effective::Asset.string_base_path) puts "String-based Asset processing and uploading..." asset.data.cache_stored_file! asset.data.retrieve_from_cache!(asset.data.cache_name) asset.data.recreate_versions! elsif asset.upload_file.include?(Effective::Asset.s3_base_path) puts "S3 Uploaded Asset downloading and processing..." # Carrierwave must download the file, process it, then upload the generated versions to S3 # We only want to process if it's an image, so we don't download zips or videos asset.remote_data_url = asset.url if asset.image? else puts "Non S3 Asset downloading and processing..." puts "Downloading #{asset.url}" # Carrierwave must download the file, process it, then upload it and generated verions to S3 # We only want to process if it's an image, so we don't download zips or videos asset.remote_data_url = asset.upload_file end asset.processed = true asset.save! (GC.start rescue nil) puts "Successfully processed the asset." end end handle_asynchronously :process_asset def reprocess_asset(id) Rails.logger.info "Processing ##{id}..." print "Processing ##{id}..." begin Effective::Asset.find(id).reprocess! Rails.logger.info "Successfully processed ##{id}" print "success"; puts '' rescue => e Rails.logger.info "Error: #{id} -> #{e.to_s}" print "error: #{e.to_s}"; puts '' end (GC.start rescue nil) end handle_asynchronously :reprocess_asset end end