Delayed::Paperclip

Delayed_paperclip lets you process your Paperclip attachments in a background task with delayed_job or Resque.

Why?

The most common use case for Paperclip is to easily attach image files to ActiveRecord models. Most of the time these image files will have multiple styles and will need to be resized when they are created. This is usually a pretty slow operation and should be handled in a background task.

I’m sure that everyone knows this, this gem just makes it easy to do.

Installation

Install the gem:

sudo gem install delayed_paperclip

Add it to your environment.rb:

config.gem 'delayed_paperclip'

Or, even better, to your Gemfile:

source "http://gemcutter.org"
gem 'delayed_paperclip'

Or install as a rails plugin:

script/plugin install git://github.com/jstorimer/delayed_paperclip.git

Dependencies:

  • Paperclip
  • DJ or Resque

Usage

In your model:


  class User < ActiveRecord::Base
    has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
    
    process_in_background :avatar
  end  

Use your Paperclip attachment just like always in controllers and views.

To select between using Resque or Delayed::Job, just install and configure your choice properly within your application, and delayed_paperclip will do the rest. It will detect which library is loaded and make a decision about which sort of job to enqueue at that time.

Resque

Make sure that you have Resque up and running. The jobs will be dispatched to the :paperclip queue, so you can correctly dispatch your worker. Configure resque and your workers exactly as you would otherwise.

DJ

Just make sure that you have DJ up and running.

What if I’m not using images?

AFAIK this library should work no matter what kind of post-processing you are doing with Paperclip.

Does it work with s3?

Yes.