Giter VIP home page Giter VIP logo

carrierwave_backgrounder's Introduction

CarrierWave Backgrounder Build Status

I like CarrierWave. That being said, I don't like tying up app instances waiting for images to process.

This gem addresses that issue by disabling processing until a background process initiates it. It supports Delayed Job, Resque and Girl Friday.

Background options

There are currently two offerings for backgrounding upload tasks which are as follows;

Backgrounder::ORM::Base::process_in_background

This method stores the original file and does no processing or versioning. Optionally you can add a column to the database which will be set to nil when the background processing is complete.

Backgrounder::ORM::Base::store_in_background

This method does nothing to the file after it is cached which makes it super fast. It requires a column in the database which stores the cache location set by carrierwave. The drawback to using this method is the need for a central location to store the cached files. This leave heroku out. Heroku may deploy workers on separate servers from where your dyno cached the files. That being said, I only recommend using this method if you have full control over your temp storage directory.

Installation

These instructions assume you have previously set up CarrierWave and DelayedJob or Resque

In Rails, add the following your Gemfile:

gem 'carrierwave_backgrounder'

Getting Started

In your CarrierWave uploader file:

class AvatarUploader < CarrierWave::Uploader::Base
  include ::CarrierWave::Backgrounder::Delay

  #etc...
end

To use process_in_background

In your model:

mount_uploader :avatar, AvatarUploader
process_in_background :avatar

Optionally you can add a column to the database which will be set to nil when the background processing is complete.

add_column :users, :avatar_processing, :boolean

To use store_in_background

In your model:

mount_uploader :avatar, AvatarUploader
store_in_background :avatar

Add a column to the model you want to background which will store the temp file location:

add_column :users, :avatar_tmp, :string

Usage Tips

If you need to process/store the upload immediately:

@user.process_<column>_upload = true

To overide the worker in cases where additional methods need to be called or you have app specific requirements, pass the worker class as the second argument:

process_in_background :avatar, MyAppsAwesomeProcessingWorker

ORM

Currently ActiveRecord is the default orm and I have not tested this with others but it should work by adding the following to your carrierwave initializer:

DataMapper::Model.send(:include, ::CarrierWave::Backgrounder::ORM::Base)
# or
Mongoid::Document::ClassMethods.send(:include, ::CarrierWave::Backgrounder::ORM::Base)
# or
Sequel::Model.send(:extend, ::CarrierWave::Backgrounder::ORM::Base)

Contributions are gladly accepted from those who use these orms.

License

Copyright (c) 2011 Larry Sprock

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

carrierwave_backgrounder's People

Contributors

andruby avatar eostrom avatar ihower avatar lardawge avatar rodacato avatar yortz avatar

Stargazers

 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.