Created
September 6, 2011 14:17
Revisions
-
andreaseger created this gist
Sep 6, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..' rails_env = ENV['RAILS_ENV'] || 'development' resque_config = YAML.load_file(rails_root + '/config/resque.yml') Resque.redis = resque_config[rails_env] #secure the admin view of resque Resque::Server.use(Rack::Auth::Basic) do |user, password| password == "secret" end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ development: localhost:6379:6 test: localhost:6379:12 production: localhost:6379:3 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ module CarrierWave module Resque module Job module ActiveRecordInterface def delay_carrierwave @delay_carrierwave ||= true end def delay_carrierwave=(delay) @delay_carrierwave = delay end end def self.included(base) base.extend ClassMethods end module ClassMethods def self.extended(base) base.send(:include, InstanceMethods) base.alias_method_chain :process!, :delay ::ActiveRecord::Base.send(:include, CarrierWave::Resque::Job::ActiveRecordInterface) end module InstanceMethods def process_with_delay!(new_file) process_without_delay!(new_file) unless model.delay_carrierwave end end end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ require "resque/tasks" #to load the rails env in every worker task "resque:setup" => :environment This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ ## at some point do this(id is my picture_id) Resque.enqueue(ImageProcessor, id) #mount the nice user interface(add this to config/routes.rb) mount Resque::Server.new, :at => '/resque' This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ class ImageProcessor @queue = :image_proccesor_queue def self.perform(picture_id) picture = Picture.find(picture_id) `convert public#{picture.image_url} -resize 64x64\\> public#{picture.image_url(:thumb)}` end end ### or better but didn't work or me class ImageProcessor @queue = :image_proccesor_queue def self.perform(picture_id) picture = Picture.find(picture_id) picture.image.versions.each_pair do |key,value| value.process_without_delay! end end end