3

I am using the latest versions of both Paperclip (v5.0.0) and Delayed_Paperclip (v3) on Rails 4.2

Everything is working fine except Delayed_Paperclip is not processing the files in the background:

Userfile.rb

class Userfile < ActiveRecord::Base

  has_attached_file :userfile,
    path: ':get_dir_path/:style_:normalized_file_name',
    url: ':get_dir_path/:style_:normalized_file_name',
    use_timestamp: false,
    styles: lambda { |a| a.instance.check_file_type[:styles] },
    only_process: lambda { |a| a.instance.check_file_type[:foreground] },
    source_file_options: { all: '-auto-orient' }

  validates_attachment_content_type :userfile, content_type: /.*/

  process_in_background :userfile,
    processing_image_url: lambda { |a|
      f = a.instance
      f.check_file_type[:processing_image_url].call(f)
    },
    only_process: lambda { |a| a.instance.check_file_type[:background] }

  def check_file_type
    if image?
      {
        styles: {
          resized: '800x600',
          resized_watermark: {
            ...
          },
          thumbnail: {
            ...
          }
        },
        foreground: [:resized, :resized_watermark, :thumbnail],
        background: [],
        processing_image_url: lambda { |f| f.actual_path :resized }
      }
    elsif video?
      {
        styles: {
          screenshot: ['300x300', :jpg],
          thumbnail: {
            ...
          },
          preview: {
            ...
          },
          mp4: {
            ...
          }
        },
        foreground: [:screenshot, :thumbnail],
        background: [:preview, :mp4],
        processing_image_url: lambda { |f| f.actual_path :screenshot }
      }
    elsif audio?
      {
        styles: {
          preview: {
            ...
          },
          mp3: {
            ...
          }
        },
        foreground: [],
        background: [:preview, :mp3],
        processing_image_url: lambda { |f| f.actual_path }
      }
    else
      {}
    end
  end

end

Now this all works except for the fact that the ActiveJob that Delayed_Paperclip creates, runs immediately on the same request. Is there something I'm missing to have in process the files after the initial request?

Noah Passalacqua
  • 742
  • 1
  • 8
  • 24

0 Answers0