Coder Social home page Coder Social logo

csolg / mongoid_paperclip_queue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kellym/mongoid_paperclip_queue

0.0 2.0 0.0 32 KB

Process your Paperclip attachments in the background using Mongoid and Resque.

Home Page: http://github.com/kellym/mongoid_paperclip_queue

License: Other

Ruby 100.00%

mongoid_paperclip_queue's Introduction

Mongoid::PaperclipQueue

Mongoid::PaperclipQueue is a complete rewrite of Delayed_Paperclip and Mongoid_Paperclip to allow those of us using Mongoid to process Paperclip attachments in the background using Resque.

Why?

We all know how important it is to keep our page load times down, so this allows us to dump all that processing to Resque to perform in the background.

Installation

Install the gem:

sudo gem install mongoid_paperclip_queue

Or for Rails 3, to your Gemfile:

gem 'mongoid_paperclip_queue'

Dependencies:

  • Mongoid
  • Paperclip
  • Resque

You don’t need to include paperclip in your Gemfile.

Usage

In your model:


  class User 
    include Mongoid::Document
    extend Mongoid::PaperclipQueue

    has_queued_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }

  end

  # You can also embed attachments, too.
  class Team 
    include Mongoid::Document
    embeds_many :users, :cascade_callbacks => true # this will save all the attachments when Team is saved.
  end

  

Paperclip will behave exactly like they describe.

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.

Detect the processing state

Processing detection is built in. We take advantage of Redis since it should already be running, and we can keep our #{attachment_name}_processing field out of our MongoDB and into a more temporary key store. The temporary image url isn’t saved anywhere, so you’ll have to specify that on your own, but it’s easy to use:


  @user = User.find(1)
  url = @user.avatar.processing? ? "/images/missing.png" : @user.avatar.url

Contributing

Checkout out CONTRIBUTING for more info.

mongoid_paperclip_queue's People

Contributors

kellym avatar mathieuravaux avatar sberryman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.