carrierwave_backgrounder 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -3
- data/README.md +15 -5
- data/lib/backgrounder/orm/activemodel.rb +14 -20
- data/lib/backgrounder/orm/base.rb +5 -6
- data/lib/backgrounder/orm/data_mapper.rb +6 -4
- data/lib/backgrounder/support/backends.rb +66 -55
- data/lib/backgrounder/version.rb +1 -1
- data/lib/backgrounder/workers/store_asset.rb +1 -0
- data/lib/carrierwave_backgrounder.rb +2 -7
- data/lib/generators/carrierwave_backgrounder/templates/config/initializers/carrierwave_backgrounder.rb +1 -0
- data/spec/backgrounder/orm/activemodel_spec.rb +13 -0
- data/spec/backgrounder/support/backends_spec.rb +169 -141
- data/spec/support/backend_constants.rb +14 -1
- metadata +5 -5
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# CarrierWave Backgrounder
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/lardawge/carrierwave_backgrounder.png)](http://travis-ci.org/lardawge/carrierwave_backgrounder)
|
4
|
-
[![Code
|
4
|
+
[![Code Climate](https://codeclimate.com/github/lardawge/carrierwave_backgrounder.png)](https://codeclimate.com/github/lardawge/carrierwave_backgrounder)
|
5
5
|
[![Still Maintained](http://stillmaintained.com/lardawge/carrierwave_backgrounder.png)](http://stillmaintained.com/lardawge/carrierwave_backgrounder)
|
6
6
|
|
7
7
|
I like CarrierWave. That being said, I don't like tying up app instances waiting for images to process.
|
@@ -58,13 +58,14 @@ end
|
|
58
58
|
For SuckerPunch, you have to configure your queue with a specific worker.
|
59
59
|
|
60
60
|
```ruby
|
61
|
-
SuckerPunch.config do
|
62
|
-
queue name: :carrierwave, worker: CarrierWave::Workers::StoreAsset, size: 2
|
63
|
-
end
|
64
|
-
|
65
61
|
CarrierWave::Backgrounder.configure do |c|
|
66
62
|
c.backend :sucker_punch, queue: :carrierwave
|
67
63
|
end
|
64
|
+
|
65
|
+
# It is important to configure sucker_punch after carrierwave_backgrounder
|
66
|
+
SuckerPunch.config do
|
67
|
+
queue name: :carrierwave, worker: CarrierWave::Workers::StoreAsset, size: 2
|
68
|
+
end
|
68
69
|
```
|
69
70
|
|
70
71
|
|
@@ -117,6 +118,15 @@ If you need to process/store the upload immediately:
|
|
117
118
|
@user.process_<column>_upload = true
|
118
119
|
```
|
119
120
|
|
121
|
+
This must be set before you assign an upload:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# In a controller
|
125
|
+
@user = User.new
|
126
|
+
@user.process_avatar_upload = true
|
127
|
+
@user.attributes = params[:user]
|
128
|
+
```
|
129
|
+
|
120
130
|
### Override worker
|
121
131
|
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
|
122
132
|
second argument:
|
@@ -7,36 +7,30 @@ module CarrierWave
|
|
7
7
|
module ActiveModel
|
8
8
|
include CarrierWave::Backgrounder::ORM::Base
|
9
9
|
|
10
|
-
def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset)
|
11
|
-
before_save :"set_#{column}_processing", :if => :"enqueue_#{column}_background_job?"
|
12
|
-
send _supported_am_after_callback, :"enqueue_#{column}_background_job", :if => :"enqueue_#{column}_background_job?"
|
13
|
-
super
|
14
|
-
end
|
15
|
-
|
16
|
-
def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset)
|
17
|
-
send _supported_am_after_callback, :"enqueue_#{column}_background_job", :if => :"enqueue_#{column}_background_job?"
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
10
|
private
|
22
11
|
|
23
|
-
def _supported_am_after_callback
|
24
|
-
respond_to?(:after_commit) ? :after_commit : :after_save
|
25
|
-
end
|
26
|
-
|
27
12
|
def _define_shared_backgrounder_methods(mod, column, worker)
|
13
|
+
before_save :"set_#{column}_processing", :if => :"enqueue_#{column}_background_job?"
|
14
|
+
send _supported_callback, :"enqueue_#{column}_background_job", :if => :"enqueue_#{column}_background_job?"
|
15
|
+
|
28
16
|
super
|
29
17
|
|
30
18
|
define_method :"#{column}_updated?" do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
send(:"#{
|
19
|
+
options = self.class.uploader_options[column] || {}
|
20
|
+
serialization_column = options[:mount_on] || column
|
21
|
+
|
22
|
+
send(:"#{serialization_column}_changed?") || # after_save support
|
23
|
+
previous_changes.has_key?(:"#{serialization_column}") || # after_commit support
|
24
|
+
send(:"remote_#{column}_url").present? || # Remote upload support
|
25
|
+
send(:"#{column}_cache").present? # Form failure support
|
35
26
|
end
|
36
27
|
end
|
28
|
+
|
29
|
+
def _supported_callback
|
30
|
+
respond_to?(:after_commit) ? :after_commit : :after_save
|
31
|
+
end
|
37
32
|
end # ActiveModel
|
38
33
|
|
39
34
|
end # ORM
|
40
35
|
end # Backgrounder
|
41
36
|
end # CarrierWave
|
42
|
-
|
@@ -43,11 +43,6 @@ module CarrierWave
|
|
43
43
|
|
44
44
|
mod = Module.new
|
45
45
|
include mod
|
46
|
-
mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
47
|
-
def set_#{column}_processing
|
48
|
-
self.#{column}_processing = true if respond_to?(:#{column}_processing)
|
49
|
-
end
|
50
|
-
RUBY
|
51
46
|
|
52
47
|
_define_shared_backgrounder_methods(mod, column, worker)
|
53
48
|
end
|
@@ -88,6 +83,7 @@ module CarrierWave
|
|
88
83
|
def store_#{column}!
|
89
84
|
super if process_#{column}_upload
|
90
85
|
end
|
86
|
+
|
91
87
|
RUBY
|
92
88
|
|
93
89
|
_define_shared_backgrounder_methods(mod, column, worker)
|
@@ -99,6 +95,10 @@ module CarrierWave
|
|
99
95
|
mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
100
96
|
def #{column}_updated?; true; end
|
101
97
|
|
98
|
+
def set_#{column}_processing
|
99
|
+
self.#{column}_processing = true if respond_to?(:#{column}_processing)
|
100
|
+
end
|
101
|
+
|
102
102
|
def enqueue_#{column}_background_job?
|
103
103
|
!remove_#{column}? && !process_#{column}_upload && #{column}_updated?
|
104
104
|
end
|
@@ -108,7 +108,6 @@ module CarrierWave
|
|
108
108
|
end
|
109
109
|
RUBY
|
110
110
|
end
|
111
|
-
|
112
111
|
end # Base
|
113
112
|
|
114
113
|
end #ORM
|
@@ -6,8 +6,7 @@ module CarrierWave
|
|
6
6
|
include CarrierWave::Backgrounder::ORM::Base
|
7
7
|
|
8
8
|
def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset)
|
9
|
-
|
10
|
-
after :save, :"enqueue_#{column}_background_job"
|
9
|
+
super
|
11
10
|
|
12
11
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
13
12
|
def set_#{column}_processing
|
@@ -18,8 +17,7 @@ module CarrierWave
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset)
|
21
|
-
|
22
|
-
after :save, :"enqueue_#{column}_background_job"
|
20
|
+
super
|
23
21
|
|
24
22
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
25
23
|
def set_#{column}_changed
|
@@ -36,7 +34,11 @@ module CarrierWave
|
|
36
34
|
private
|
37
35
|
|
38
36
|
def _define_shared_backgrounder_methods(mod, column, worker)
|
37
|
+
before :save, :"set_#{column}_changed"
|
38
|
+
after :save, :"enqueue_#{column}_background_job"
|
39
|
+
|
39
40
|
super
|
41
|
+
|
40
42
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
41
43
|
attr_reader :#{column}_changed
|
42
44
|
|
@@ -1,72 +1,83 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module CarrierWave
|
2
|
+
module Backgrounder
|
3
|
+
module Support
|
4
|
+
module Backends
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
module ClassMethods
|
11
|
+
attr_reader :queue_options
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def backend(queue_name=nil, args={})
|
14
|
+
return @backend if @backend
|
15
|
+
@queue_options = args
|
16
|
+
@backend = queue_name
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
def enqueue_for_backend(worker, class_name, subject_id, mounted_as)
|
20
|
+
self.send :"enqueue_#{backend}", worker, class_name, subject_id, mounted_as
|
21
|
+
end
|
20
22
|
|
21
|
-
|
23
|
+
private
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
def enqueue_delayed_job(worker, *args)
|
26
|
+
if ::Delayed::Job.new.respond_to?(:queue)
|
27
|
+
::Delayed::Job.enqueue worker.new(*args), :queue => queue_options[:queue]
|
28
|
+
else
|
29
|
+
::Delayed::Job.enqueue worker.new(*args)
|
30
|
+
if queue_options[:queue]
|
31
|
+
::Rails.logger.warn("Queue name given but no queue column exists for Delayed::Job")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
36
|
+
def enqueue_resque(worker, *args)
|
37
|
+
worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
|
38
|
+
::Resque.enqueue worker, *args
|
39
|
+
end
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
41
|
+
def enqueue_sidekiq(worker, *args)
|
42
|
+
args = sidekiq_queue_options('class' => worker, 'args' => args)
|
43
|
+
worker.client_push(args)
|
44
|
+
end
|
36
45
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
46
|
+
def enqueue_girl_friday(worker, *args)
|
47
|
+
@girl_friday_queue ||= GirlFriday::WorkQueue.new(queue_options.delete(:queue) || :carrierwave, queue_options) do |msg|
|
48
|
+
worker = msg[:worker]
|
49
|
+
worker.perform
|
50
|
+
end
|
51
|
+
@girl_friday_queue << { :worker => worker.new(*args) }
|
52
|
+
end
|
44
53
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
54
|
+
def enqueue_sucker_punch(worker, *args)
|
55
|
+
@sucker_punch_queue ||= SuckerPunch::Queue[queue_options[:queue] || :carrierwave]
|
56
|
+
@sucker_punch_queue.async.perform(*args)
|
57
|
+
end
|
49
58
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
59
|
+
def enqueue_qu(worker, *args)
|
60
|
+
worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
|
61
|
+
::Qu.enqueue worker, *args
|
62
|
+
end
|
54
63
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
64
|
+
def enqueue_qc(worker, *args)
|
65
|
+
class_name, subject_id, mounted_as = args
|
66
|
+
::QC.enqueue "#{worker.name}.perform", class_name, subject_id, mounted_as.to_s
|
67
|
+
end
|
59
68
|
|
60
|
-
|
61
|
-
|
62
|
-
|
69
|
+
def enqueue_immediate(worker, *args)
|
70
|
+
worker.new(*args).perform
|
71
|
+
end
|
63
72
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
73
|
+
def sidekiq_queue_options(args)
|
74
|
+
args['queue'] = queue_options[:queue] if queue_options[:queue]
|
75
|
+
args['retry'] = queue_options[:retry] unless queue_options[:retry].nil?
|
76
|
+
args['timeout'] = queue_options[:timeout] if queue_options[:timeout]
|
77
|
+
args['backtrace'] = queue_options[:backtrace] if queue_options[:backtrace]
|
78
|
+
args
|
79
|
+
end
|
80
|
+
end
|
70
81
|
end
|
71
82
|
end
|
72
83
|
end
|
data/lib/backgrounder/version.rb
CHANGED
@@ -17,6 +17,7 @@ module CarrierWave
|
|
17
17
|
store_directories(record)
|
18
18
|
record.send :"process_#{column}_upload=", true
|
19
19
|
record.send :"#{column}_tmp=", nil
|
20
|
+
record.send :"#{column}_processing=", nil if record.respond_to?(:"#{column}_processing")
|
20
21
|
File.open(cache_path) { |f| record.send :"#{column}=", f }
|
21
22
|
if record.save!
|
22
23
|
FileUtils.rm_r(tmp_directory, :force => true)
|
@@ -7,28 +7,23 @@ module CarrierWave
|
|
7
7
|
module Backgrounder
|
8
8
|
include Support::Backends
|
9
9
|
|
10
|
-
class UnsupportedBackendError < StandardError ; end
|
11
|
-
class TooManyBackendsAvailableError < StandardError ; end
|
12
|
-
|
13
10
|
def self.configure
|
14
11
|
yield self
|
15
12
|
case @backend
|
16
13
|
when :sidekiq
|
14
|
+
require 'sidekiq'
|
17
15
|
::CarrierWave::Workers::ProcessAsset.class_eval do
|
18
|
-
require 'sidekiq'
|
19
16
|
include ::Sidekiq::Worker
|
20
17
|
end
|
21
18
|
::CarrierWave::Workers::StoreAsset.class_eval do
|
22
|
-
require 'sidekiq'
|
23
19
|
include ::Sidekiq::Worker
|
24
20
|
end
|
25
21
|
when :sucker_punch
|
22
|
+
require 'sucker_punch'
|
26
23
|
::CarrierWave::Workers::ProcessAsset.class_eval do
|
27
|
-
require 'sucker_punch'
|
28
24
|
include ::SuckerPunch::Worker
|
29
25
|
end
|
30
26
|
::CarrierWave::Workers::StoreAsset.class_eval do
|
31
|
-
require 'sucker_punch'
|
32
27
|
include ::SuckerPunch::Worker
|
33
28
|
end
|
34
29
|
end
|
@@ -3,6 +3,7 @@ CarrierWave::Backgrounder.configure do |c|
|
|
3
3
|
# c.backend :resque, queue: :carrierwave
|
4
4
|
# c.backend :sidekiq, queue: :carrierwave
|
5
5
|
# c.backend :girl_friday, queue: :carrierwave
|
6
|
+
# c.backend :sucker_punch, queue: :carrierwave
|
6
7
|
# c.backend :qu, queue: :carrierwave
|
7
8
|
# c.backend :qc
|
8
9
|
end
|
@@ -11,6 +11,7 @@ describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
11
11
|
def remote_avatar_url; OpenStruct.new(:present? => true); end
|
12
12
|
def remove_avatar?; false; end
|
13
13
|
def previous_changes; {}; end
|
14
|
+
def self.uploader_options; {}; end
|
14
15
|
end
|
15
16
|
|
16
17
|
@mock_class.extend CarrierWave::Backgrounder::ORM::ActiveModel
|
@@ -46,6 +47,18 @@ describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
46
47
|
@mock_class.process_in_background :avatar
|
47
48
|
end
|
48
49
|
|
50
|
+
context 'mount_on option is set' do
|
51
|
+
before do
|
52
|
+
options_hash = {:avatar => {:mount_on => :some_other_column}}
|
53
|
+
@mock_class.expects(:uploader_options).returns(options_hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns true if alternate column is changed" do
|
57
|
+
instance.expects(:some_other_column_changed?).returns(true)
|
58
|
+
expect(instance.avatar_updated?).to be_true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
49
62
|
it "returns true if process_avatar_upload is false" do
|
50
63
|
instance.expects(:process_avatar_upload)
|
51
64
|
expect(instance.enqueue_avatar_background_job?).to be_true
|
@@ -2,187 +2,215 @@ require 'spec_helper'
|
|
2
2
|
require 'support/backend_constants'
|
3
3
|
require 'support/mock_worker'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module CarrierWave::Backgrounder
|
6
|
+
describe Support::Backends do
|
7
|
+
let(:mock_module) { Module.new }
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'setting backend' do
|
13
|
-
it 'using #backend=' do
|
14
|
-
expect {
|
15
|
-
mock_module.backend = :delayed_job
|
16
|
-
}.to raise_error(NoMethodError)
|
9
|
+
before do
|
10
|
+
mock_module.send :include, Support::Backends
|
17
11
|
end
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
describe 'setting backend' do
|
14
|
+
it 'using #backend=' do
|
15
|
+
expect {
|
16
|
+
mock_module.backend = :delayed_job
|
17
|
+
}.to raise_error(NoMethodError)
|
18
|
+
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
it 'using #backend' do
|
21
|
+
mock_module.backend(:delayed_job)
|
22
|
+
expect(mock_module.backend).to eql(:delayed_job)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'allows passing of queue_options' do
|
26
|
+
mock_module.backend(:delayed_job, :queue => :awesome_queue)
|
27
|
+
expect(mock_module.queue_options).to eql({:queue => :awesome_queue})
|
28
|
+
end
|
27
29
|
end
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
describe '#enqueue_for_backend' do
|
32
|
+
let!(:worker) { MockWorker.new('FakeClass', 1, :image) }
|
33
|
+
|
34
|
+
context 'delayed_job' do
|
35
|
+
before do
|
36
|
+
@mock_worker = Class.new do
|
37
|
+
def self.perform(*args); new(*args).perform; end
|
38
|
+
end
|
32
39
|
|
33
|
-
|
34
|
-
before do
|
35
|
-
@mock_worker = Class.new do
|
36
|
-
def self.perform(*args); new(*args).perform; end
|
40
|
+
MockWorker.expects(:new).returns(worker)
|
37
41
|
end
|
38
42
|
|
39
|
-
|
40
|
-
|
43
|
+
context 'queue column exists' do
|
44
|
+
it 'defaults the queue name to nil if none passed to #backend' do
|
45
|
+
mock_module.backend :delayed_job
|
46
|
+
Delayed::Job.expects(:enqueue).with(worker, :queue => nil)
|
47
|
+
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'sets the queue name to the queue name passed to #backend' do
|
51
|
+
mock_module.backend :delayed_job, :queue => :awesome_queue
|
52
|
+
Delayed::Job.expects(:enqueue).with(worker, :queue => :awesome_queue)
|
53
|
+
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
54
|
+
end
|
55
|
+
end
|
41
56
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
57
|
+
context 'queue column does not exist' do
|
58
|
+
before do
|
59
|
+
column_names = Delayed::Job.column_names.tap { |cn| cn.delete('queue') }
|
60
|
+
Delayed::Job.stubs(:column_names).returns(column_names)
|
61
|
+
Delayed::Job.class_eval { remove_method(:queue) }
|
62
|
+
end
|
63
|
+
|
64
|
+
after do
|
65
|
+
Delayed::Job.class_eval { define_method(:queue) { nil } }
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'does not pass a queue name if none passed to #backend' do
|
69
|
+
mock_module.backend :delayed_job
|
70
|
+
Delayed::Job.expects(:enqueue).with(worker)
|
71
|
+
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'does not pass a queue name and logs a warning message if a queue name is passed to #backend' do
|
75
|
+
mock_module.backend :delayed_job, :queue => :awesome_queue
|
76
|
+
Delayed::Job.expects(:enqueue).with(worker)
|
77
|
+
Rails.logger.expects(:warn).with(instance_of(String))
|
78
|
+
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
79
|
+
end
|
80
|
+
end
|
46
81
|
end
|
47
82
|
|
48
|
-
|
49
|
-
|
50
|
-
Delayed::Job.expects(:enqueue).with(worker, :queue => :awesome_queue)
|
51
|
-
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
52
|
-
end
|
53
|
-
end
|
83
|
+
context 'resque' do
|
84
|
+
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
54
85
|
|
55
|
-
|
56
|
-
|
86
|
+
before do
|
87
|
+
Resque.expects(:enqueue).with(*args)
|
88
|
+
end
|
57
89
|
|
58
|
-
|
59
|
-
|
60
|
-
|
90
|
+
it 'sets a variable with the queue name, defaults to :carrierwave' do
|
91
|
+
mock_module.backend :resque
|
92
|
+
mock_module.enqueue_for_backend(*args)
|
93
|
+
expect(MockWorker.instance_variable_get '@queue').to eql(:carrierwave)
|
94
|
+
end
|
61
95
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
96
|
+
it 'sets a variable to the queue name passed to #backend' do
|
97
|
+
mock_module.backend :resque, :queue => :awesome_queue
|
98
|
+
mock_module.enqueue_for_backend(*args)
|
99
|
+
expect(MockWorker.instance_variable_get '@queue').to eql(:awesome_queue)
|
100
|
+
end
|
66
101
|
end
|
67
102
|
|
68
|
-
|
69
|
-
|
70
|
-
mock_module.enqueue_for_backend(*args)
|
71
|
-
expect(MockWorker.instance_variable_get '@queue').to eql(:awesome_queue)
|
72
|
-
end
|
73
|
-
end
|
103
|
+
context 'sidekiq' do
|
104
|
+
let(:args) { ['FakeClass', 1, :image] }
|
74
105
|
|
75
|
-
|
76
|
-
|
106
|
+
it 'invokes client_push on the class with passed args' do
|
107
|
+
MockSidekiqWorker.expects(:client_push).with({ 'class' => MockSidekiqWorker, 'args' => args })
|
108
|
+
mock_module.backend :sidekiq
|
109
|
+
mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
|
110
|
+
end
|
77
111
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
112
|
+
it 'invokes client_push and includes the options passed to backend' do
|
113
|
+
MockSidekiqWorker.expects(:client_push).with({ 'class' => MockSidekiqWorker,
|
114
|
+
'retry' => false,
|
115
|
+
'timeout' => 60,
|
116
|
+
'queue' => :awesome_queue,
|
117
|
+
'args' => args })
|
118
|
+
options = {:retry => false, :timeout => 60, :queue => :awesome_queue}
|
119
|
+
mock_module.backend :sidekiq, options
|
120
|
+
mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
|
121
|
+
end
|
82
122
|
end
|
83
123
|
|
84
|
-
|
85
|
-
|
86
|
-
'retry' => false,
|
87
|
-
'timeout' => 60,
|
88
|
-
'queue' => :awesome_queue,
|
89
|
-
'args' => args })
|
90
|
-
options = {:retry => false, :timeout => 60, :queue => :awesome_queue}
|
91
|
-
mock_module.backend :sidekiq, options
|
92
|
-
mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
|
93
|
-
end
|
94
|
-
end
|
124
|
+
context 'girl_friday' do
|
125
|
+
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
95
126
|
|
96
|
-
|
97
|
-
|
127
|
+
it 'instantiates a GirlFriday work queue if one does not exist' do
|
128
|
+
mock_module.backend :girl_friday
|
129
|
+
GirlFriday::WorkQueue.expects(:new).with(:carrierwave, {}).returns([])
|
130
|
+
mock_module.enqueue_for_backend(*args)
|
131
|
+
end
|
98
132
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
133
|
+
it 'instantiates a GirlFriday work queue passing the args to the queue' do
|
134
|
+
mock_module.backend :girl_friday, :queue => :awesome_queue, :size => 3
|
135
|
+
GirlFriday::WorkQueue.expects(:new).with(:awesome_queue, {:size => 3}).returns([])
|
136
|
+
mock_module.enqueue_for_backend(*args)
|
137
|
+
end
|
104
138
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
139
|
+
it 'does not instantiate a GirlFriday work queue if one exists' do
|
140
|
+
mock_module.backend :girl_friday
|
141
|
+
mock_module.instance_variable_set('@girl_friday_queue', [])
|
142
|
+
GirlFriday::WorkQueue.expects(:new).never
|
143
|
+
mock_module.enqueue_for_backend(*args)
|
144
|
+
end
|
110
145
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
146
|
+
it 'add a worker to the girl_friday queue' do
|
147
|
+
expected = [{ :worker => MockWorker.new('FakeClass', 1, :image) }]
|
148
|
+
mock_module.backend :girl_friday
|
149
|
+
mock_module.instance_variable_set('@girl_friday_queue', [])
|
150
|
+
mock_module.enqueue_for_backend(*args)
|
151
|
+
expect(mock_module.instance_variable_get '@girl_friday_queue').to eql(expected)
|
152
|
+
end
|
116
153
|
end
|
117
154
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
mock_module.instance_variable_set('@girl_friday_queue', [])
|
122
|
-
mock_module.enqueue_for_backend(*args)
|
123
|
-
expect(mock_module.instance_variable_get '@girl_friday_queue').to eql(expected)
|
124
|
-
end
|
125
|
-
end
|
155
|
+
context 'sucker_punch' do
|
156
|
+
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
157
|
+
let(:mock_sp) { mock('SuckerPunch')}
|
126
158
|
|
127
|
-
|
128
|
-
|
129
|
-
|
159
|
+
before do
|
160
|
+
mock_sp.expects(:async).returns(mock_sp)
|
161
|
+
mock_sp.expects(:perform).with('FakeClass', 1, :image)
|
162
|
+
end
|
130
163
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
164
|
+
it 'sets the queue to :carrierwave by default' do
|
165
|
+
SuckerPunch::Queue.expects(:[]).with(:carrierwave).returns(mock_sp)
|
166
|
+
mock_module.backend :sucker_punch
|
167
|
+
mock_module.enqueue_for_backend(*args)
|
168
|
+
end
|
135
169
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
170
|
+
it 'sets the queue to backend :queue option' do
|
171
|
+
SuckerPunch::Queue.expects(:[]).with(:awesome_queue).returns(mock_sp)
|
172
|
+
mock_module.backend :sucker_punch, :queue => :awesome_queue
|
173
|
+
mock_module.enqueue_for_backend(*args)
|
174
|
+
end
|
140
175
|
end
|
141
176
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
177
|
+
context 'qu' do
|
178
|
+
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
179
|
+
before do
|
180
|
+
Qu.expects(:enqueue).with(*args)
|
181
|
+
end
|
148
182
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
183
|
+
it 'sets a variable with the queue name, defaults to :carrierwave' do
|
184
|
+
mock_module.backend :qu
|
185
|
+
mock_module.enqueue_for_backend(*args)
|
186
|
+
expect(MockWorker.instance_variable_get '@queue').to eql(:carrierwave)
|
187
|
+
end
|
154
188
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
189
|
+
it 'sets a variable to the queue name passed to #backend' do
|
190
|
+
mock_module.backend :qu, :queue => :awesome_queue
|
191
|
+
mock_module.enqueue_for_backend(*args)
|
192
|
+
expect(MockWorker.instance_variable_get '@queue').to eql(:awesome_queue)
|
193
|
+
end
|
159
194
|
end
|
160
195
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
196
|
+
context 'qc' do
|
197
|
+
it 'calls enqueue with the passed args' do
|
198
|
+
QC.expects(:enqueue).with("MockWorker.perform", 'FakeClass', 1, 'image')
|
199
|
+
mock_module.backend :qc
|
200
|
+
mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
|
201
|
+
end
|
165
202
|
end
|
166
|
-
end
|
167
203
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
204
|
+
context 'immediate' do
|
205
|
+
it 'instantiates a worker passing the args and calls perform' do
|
206
|
+
worker = mock('Worker')
|
207
|
+
MockWorker.expects(:new).with('FakeClass', 1, :image).returns(worker)
|
208
|
+
worker.expects(:perform)
|
209
|
+
mock_module.backend :immediate
|
210
|
+
mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
|
211
|
+
end
|
173
212
|
end
|
174
|
-
end
|
175
213
|
|
176
|
-
context 'immediate' do
|
177
|
-
it 'instantiates a worker passing the args and calls perform' do
|
178
|
-
worker = mock('Worker')
|
179
|
-
MockWorker.expects(:new).with('FakeClass', 1, :image).returns(worker)
|
180
|
-
worker.expects(:perform)
|
181
|
-
mock_module.backend :immediate
|
182
|
-
mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
|
183
|
-
end
|
184
214
|
end
|
185
|
-
|
186
215
|
end
|
187
216
|
end
|
188
|
-
|
@@ -6,7 +6,14 @@ module GirlFriday
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module Delayed
|
9
|
-
|
9
|
+
class Job
|
10
|
+
def self.column_names
|
11
|
+
%w(id priority attempts handler queue last_error run_at locked_at failed_at locked_by created_at updated_at)
|
12
|
+
end
|
13
|
+
|
14
|
+
column_names.each do |column_name|
|
15
|
+
define_method(column_name) { nil }
|
16
|
+
end
|
10
17
|
end
|
11
18
|
end
|
12
19
|
|
@@ -42,3 +49,9 @@ module SuckerPunch
|
|
42
49
|
class Queue
|
43
50
|
end
|
44
51
|
end
|
52
|
+
|
53
|
+
module Rails
|
54
|
+
def self.logger
|
55
|
+
@logger ||= Object.new
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave_backgrounder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
segments:
|
130
130
|
- 0
|
131
|
-
hash:
|
131
|
+
hash: -3663801014250958457
|
132
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
133
|
none: false
|
134
134
|
requirements:
|
@@ -137,10 +137,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
version: '0'
|
138
138
|
segments:
|
139
139
|
- 0
|
140
|
-
hash:
|
140
|
+
hash: -3663801014250958457
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 1.8.
|
143
|
+
rubygems_version: 1.8.25
|
144
144
|
signing_key:
|
145
145
|
specification_version: 3
|
146
146
|
summary: Offload CarrierWave's image processing and storage to a background process
|