delayed_pa​​perclip没有在后台运行

时间:2016-07-09 00:11:11

标签: paperclip ruby-on-rails-4.2 rails-activejob delayed-paperclip

我在Rails 4.2上使用Paperclip(v5.0.0)和Delayed_Paperclip(v3)的最新版本

除了Delayed_Paperclip没有在后台处理文件外,一切正常:

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

现在这一切都有效,除了Delayed_Paperclip创建的ActiveJob,在同一请求上立即运行。在初始请求之后,我是否缺少处理文件的东西?

0 个答案:

没有答案