Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Commit

Permalink
Merge pull request #111 from katafrakt/active_job
Browse files Browse the repository at this point in the history
support for active job
  • Loading branch information
ScotterC committed Oct 28, 2014
2 parents b77ef65 + e1937b6 commit 6d70ab0
Show file tree
Hide file tree
Showing 20 changed files with 334 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ gemfile:
- gemfiles/rails3_1.gemfile
- gemfiles/rails3_2.gemfile
- gemfiles/rails4.gemfile
- gemfiles/rails4_2.gemfile


4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ end

appraise "rails4" do
gem "rails", "~> 4.0.3"
end

appraise "rails4_2" do
gem "rails", "~> 4.2.0.beta2"
end
4 changes: 2 additions & 2 deletions delayed_paperclip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Gem::Specification.new do |s|
s.add_dependency 'paperclip', [">= 3.3"]

s.add_development_dependency 'mocha'
s.add_development_dependency "rspec"
s.add_development_dependency "rspec", '< 3.0'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'delayed_job'
s.add_development_dependency 'delayed_job_active_record'
s.add_development_dependency 'resque'
s.add_development_dependency 'sidekiq'
s.add_development_dependency 'sidekiq', '< 3.0'
s.add_development_dependency 'appraisal'
s.add_development_dependency 'rake'
s.add_development_dependency 'bundler'
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails3_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source "http://rubygems.org"

gem "rails", "~> 3.1.12"

gemspec :path=>"../"
gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/rails3_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ DEPENDENCIES
railties
rake
resque
rspec
sidekiq
rspec (< 3.0)
sidekiq (< 3.0)
sqlite3
2 changes: 1 addition & 1 deletion gemfiles/rails3_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source "http://rubygems.org"

gem "rails", "~> 3.2.17"

gemspec :path=>"../"
gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/rails3_2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ DEPENDENCIES
railties
rake
resque
rspec
sidekiq
rspec (< 3.0)
sidekiq (< 3.0)
sqlite3
2 changes: 1 addition & 1 deletion gemfiles/rails4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source "http://rubygems.org"

gem "rails", "~> 4.0.3"

gemspec :path=>"../"
gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/rails4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ DEPENDENCIES
railties
rake
resque
rspec
sidekiq
rspec (< 3.0)
sidekiq (< 3.0)
sqlite3
7 changes: 7 additions & 0 deletions gemfiles/rails4_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "rails", "~> 4.2.0.beta2"

gemspec :path => "../"
181 changes: 181 additions & 0 deletions gemfiles/rails4_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
PATH
remote: ../
specs:
delayed_paperclip (2.8.0)
paperclip (>= 3.3)

GEM
remote: http://rubygems.org/
specs:
actionmailer (4.2.0.beta2)
actionpack (= 4.2.0.beta2)
actionview (= 4.2.0.beta2)
activejob (= 4.2.0.beta2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.3)
actionpack (4.2.0.beta2)
actionview (= 4.2.0.beta2)
activesupport (= 4.2.0.beta2)
rack (~> 1.6.0.beta)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.3)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.0.beta2)
activesupport (= 4.2.0.beta2)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.3)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.0.beta2)
activesupport (= 4.2.0.beta2)
globalid (>= 0.3.0)
activemodel (4.2.0.beta2)
activesupport (= 4.2.0.beta2)
builder (~> 3.1)
activerecord (4.2.0.beta2)
activemodel (= 4.2.0.beta2)
activesupport (= 4.2.0.beta2)
arel (>= 6.0.0.beta1, < 6.1)
activesupport (4.2.0.beta2)
i18n (>= 0.7.0.beta1, < 0.8)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
appraisal (1.0.2)
bundler
rake
thor (>= 0.14.0)
arel (6.0.0.beta1)
builder (3.2.2)
celluloid (0.15.2)
timers (~> 1.1.0)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.4)
climate_control (>= 0.0.3, < 1.0)
connection_pool (2.0.0)
delayed_job (4.0.4)
activesupport (>= 3.0, < 4.2)
delayed_job_active_record (4.0.2)
activerecord (>= 3.0, < 4.2)
delayed_job (>= 3.0, < 4.1)
diff-lcs (1.2.5)
erubis (2.7.0)
globalid (0.3.0)
activesupport (>= 4.1.0)
hike (1.2.3)
i18n (0.7.0.beta1)
json (1.8.1)
loofah (2.0.1)
nokogiri (>= 1.5.9)
mail (2.6.1)
mime-types (>= 1.16, < 3)
metaclass (0.0.4)
mime-types (2.3)
mini_portile (0.6.0)
minitest (5.4.2)
mocha (1.1.0)
metaclass (~> 0.0.1)
mono_logger (1.1.0)
multi_json (1.10.1)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
paperclip (4.2.0)
activemodel (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.5.3)
mime-types
rack (1.6.0.beta)
rack-protection (1.5.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (4.2.0.beta2)
actionmailer (= 4.2.0.beta2)
actionpack (= 4.2.0.beta2)
actionview (= 4.2.0.beta2)
activejob (= 4.2.0.beta2)
activemodel (= 4.2.0.beta2)
activerecord (= 4.2.0.beta2)
activesupport (= 4.2.0.beta2)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.0.beta2)
sprockets-rails (~> 3.0.0.beta1)
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.3)
activesupport
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1)
loofah (~> 2.0)
railties (4.2.0.beta2)
actionpack (= 4.2.0.beta2)
activesupport (= 4.2.0.beta2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
redis (3.1.0)
redis-namespace (1.5.1)
redis (~> 3.0, >= 3.0.4)
resque (1.25.2)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.3)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
sidekiq (2.17.8)
celluloid (= 0.15.2)
connection_pool (~> 2.0)
json
redis (~> 3.1)
redis-namespace (~> 1.3)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sprockets (2.12.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (3.0.0.beta1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (~> 2.8)
sqlite3 (1.3.9)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
timers (1.1.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
vegas (0.1.11)
rack (>= 1.0.0)

PLATFORMS
ruby

DEPENDENCIES
appraisal
bundler
delayed_job
delayed_job_active_record
delayed_paperclip!
mocha
rails (~> 4.2.0.beta2)
railties
rake
resque
rspec (< 3.0)
sidekiq (< 3.0)
sqlite3
1 change: 1 addition & 0 deletions lib/delayed_paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def options
end

def detect_background_task
return DelayedPaperclip::Jobs::ActiveJob if defined? ::ActiveJob::Base
return DelayedPaperclip::Jobs::DelayedJob if defined? ::Delayed::Job
return DelayedPaperclip::Jobs::Resque if defined? ::Resque
return DelayedPaperclip::Jobs::Sidekiq if defined? ::Sidekiq
Expand Down
1 change: 1 addition & 0 deletions lib/delayed_paperclip/jobs.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module DelayedPaperclip
module Jobs
autoload :ActiveJob, 'delayed_paperclip/jobs/active_job'
autoload :DelayedJob, 'delayed_paperclip/jobs/delayed_job'
autoload :Resque, 'delayed_paperclip/jobs/resque'
autoload :Sidekiq, 'delayed_paperclip/jobs/sidekiq'
Expand Down
16 changes: 16 additions & 0 deletions lib/delayed_paperclip/jobs/active_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module DelayedPaperclip
module Jobs
class ActiveJob < ActiveJob::Base
queue_as :paperclip

def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
# ActiveJob currently does not support symbol arguments
self.perform_later(instance_klass, instance_id, attachment_name.to_s)
end

def perform(instance_klass, instance_id, attachment_name)
DelayedPaperclip.process_job(instance_klass, instance_id, attachment_name.to_sym)
end
end
end
end
26 changes: 26 additions & 0 deletions spec/integration/active_job_inline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe "ActiveJob inline" do

if defined? ActiveJob
before :all do
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::ActiveJob
ActiveJob::Base.logger = nil
end

let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/spec/fixtures/12k.png")) }

describe "perform job" do
before :each do
DelayedPaperclip.options[:url_with_processing] = true
reset_dummy
end

it "performs a job" do
dummy.image = File.open("#{ROOT}/spec/fixtures/12k.png")
Paperclip::Attachment.any_instance.expects(:reprocess!)
dummy.save!
end
end
end
end
31 changes: 31 additions & 0 deletions spec/integration/active_job_resque_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'
require 'resque'

if defined? ActiveJob
describe "Active Job with Resque backend" do

before :all do
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::ActiveJob
ActiveJob::Base.logger = nil
ActiveJob::Base.queue_adapter = :resque
Resque.remove_queue(:paperclip)
end

let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/spec/fixtures/12k.png")) }

describe "integration tests" do
include_examples "base usage"
end

def process_jobs
worker = Resque::Worker.new(:paperclip)
worker.process
end

def jobs_count

Resque.size(:paperclip)
end

end
end
35 changes: 35 additions & 0 deletions spec/integration/active_job_sidekiq_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'
require 'sidekiq/api'

describe "ActiveJob with Sidekiq backend" do

if defined? ActiveJob
before :all do
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::ActiveJob
ActiveJob::Base.logger = nil
ActiveJob::Base.queue_adapter = :sidekiq
end

let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/spec/fixtures/12k.png")) }

describe "integration tests" do
include_examples "base usage"
end
end

def process_jobs
Sidekiq::Queue.new(:paperclip).each do |job|
worker = job.klass.constantize.new
args = job.args
begin
worker.perform(*args)
rescue # Assume sidekiq handle exception properly
end
job.delete
end
end

def jobs_count
Sidekiq::Queue.new(:paperclip).size
end
end
Loading

0 comments on commit 6d70ab0

Please sign in to comment.