Class: Effective::DelayedJob

Inherits:
Object
  • Object
show all
Defined in:
app/models/effective/delayed_job.rb

Instance Method Summary collapse

Instance Method Details

#process_asset(obj) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/effective/delayed_job.rb', line 7

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.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

#reprocess_asset(id) ⇒ Object



47
48
49
50
# File 'app/models/effective/delayed_job.rb', line 47

def reprocess_asset(id)
  Effective::Asset.find(id).reprocess!
  (GC.start rescue nil)
end