carrierwave_backgrounder 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/README.md +14 -1
- data/lib/backgrounder/orm/base.rb +1 -1
- data/lib/backgrounder/railtie.rb +25 -0
- data/lib/backgrounder/support/backends.rb +15 -7
- data/lib/backgrounder/version.rb +1 -1
- data/lib/carrierwave_backgrounder.rb +12 -28
- data/spec/backgrounder/orm/activemodel_spec.rb +1 -0
- data/spec/backgrounder/support/backends_spec.rb +25 -2
- data/spec/support/backend_constants.rb +5 -0
- metadata +5 -4
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.2.1
|
2
|
+
|
3
|
+
### enhancements
|
4
|
+
* [#119] Add support for SuckerPunch [rewritten].
|
5
|
+
|
6
|
+
### bug fixes
|
7
|
+
* [#115] column_remove! should not trigger a background job
|
8
|
+
* [#112] Raise a NoMethodError when using backend= instead of silent failure.
|
9
|
+
|
1
10
|
## 0.2.0
|
2
11
|
|
3
12
|
### enhancements
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
I like CarrierWave. That being said, I don't like tying up app instances waiting for images to process.
|
8
8
|
|
9
9
|
This gem addresses that by offloading processing or storage/processing to a background task.
|
10
|
-
We currently support Delayed Job, Resque, Sidekiq, Girl Friday, Qu, and Queue Classic.
|
10
|
+
We currently support Delayed Job, Resque, Sidekiq, SuckerPunch, Girl Friday, Qu, and Queue Classic.
|
11
11
|
|
12
12
|
## Background options
|
13
13
|
|
@@ -55,6 +55,19 @@ CarrierWave::Backgrounder.configure do |c|
|
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
+
For SuckerPunch, you have to configure your queue with a specific worker.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
SuckerPunch.config do
|
62
|
+
queue name: :carrierwave, worker: CarrierWave::Workers::StoreAsset, size: 2
|
63
|
+
end
|
64
|
+
|
65
|
+
CarrierWave::Backgrounder.configure do |c|
|
66
|
+
c.backend :sucker_punch, queue: :carrierwave
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
|
58
71
|
In your CarrierWave uploader file:
|
59
72
|
|
60
73
|
```ruby
|
@@ -100,7 +100,7 @@ module CarrierWave
|
|
100
100
|
def #{column}_updated?; true; end
|
101
101
|
|
102
102
|
def enqueue_#{column}_background_job?
|
103
|
-
!process_#{column}_upload && #{column}_updated?
|
103
|
+
!remove_#{column}? && !process_#{column}_upload && #{column}_updated?
|
104
104
|
end
|
105
105
|
|
106
106
|
def enqueue_#{column}_background_job
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Backgrounder
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
|
5
|
+
initializer "carrierwave_backgrounder.active_record" do
|
6
|
+
ActiveSupport.on_load :active_record do
|
7
|
+
require 'backgrounder/orm/activemodel'
|
8
|
+
::ActiveRecord::Base.extend CarrierWave::Backgrounder::ORM::ActiveModel
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer "carrierwave_backgrounder.data_mapper", :before =>"data_mapper.add_to_prepare" do
|
13
|
+
require 'backgrounder/orm/data_mapper' if defined?(DataMapper)
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer "carrierwave_backgrounder.mongoid" do
|
17
|
+
if defined?(Mongoid)
|
18
|
+
require 'backgrounder/orm/activemodel'
|
19
|
+
::Mongoid::Document::ClassMethods.send(:include, ::CarrierWave::Backgrounder::ORM::ActiveModel)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -6,7 +6,6 @@ module Support
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ClassMethods
|
9
|
-
attr_writer :backend
|
10
9
|
attr_reader :queue_options
|
11
10
|
|
12
11
|
def backend(queue_name=nil, args={})
|
@@ -31,12 +30,8 @@ module Support
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def enqueue_sidekiq(worker, *args)
|
34
|
-
|
35
|
-
|
36
|
-
sidekiq_client_args['retry'] = queue_options[:retry] unless queue_options[:retry].nil?
|
37
|
-
sidekiq_client_args['timeout'] = queue_options[:timeout] unless queue_options[:timeout].nil?
|
38
|
-
sidekiq_client_args['backtrace'] = queue_options[:backtrace] unless queue_options[:backtrace].nil?
|
39
|
-
worker.client_push(sidekiq_client_args)
|
33
|
+
args = sidekiq_queue_options('class' => worker, 'args' => args)
|
34
|
+
worker.client_push(args)
|
40
35
|
end
|
41
36
|
|
42
37
|
def enqueue_girl_friday(worker, *args)
|
@@ -47,6 +42,11 @@ module Support
|
|
47
42
|
@girl_friday_queue << { :worker => worker.new(*args) }
|
48
43
|
end
|
49
44
|
|
45
|
+
def enqueue_sucker_punch(worker, *args)
|
46
|
+
@sucker_punch_queue ||= SuckerPunch::Queue[queue_options[:queue] || :carrierwave]
|
47
|
+
@sucker_punch_queue.async.perform(*args)
|
48
|
+
end
|
49
|
+
|
50
50
|
def enqueue_qu(worker, *args)
|
51
51
|
worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
|
52
52
|
::Qu.enqueue worker, *args
|
@@ -60,6 +60,14 @@ module Support
|
|
60
60
|
def enqueue_immediate(worker, *args)
|
61
61
|
worker.new(*args).perform
|
62
62
|
end
|
63
|
+
|
64
|
+
def sidekiq_queue_options(args)
|
65
|
+
args['queue'] = queue_options[:queue] if queue_options[:queue]
|
66
|
+
args['retry'] = queue_options[:retry] unless queue_options[:retry].nil?
|
67
|
+
args['timeout'] = queue_options[:timeout] if queue_options[:timeout]
|
68
|
+
args['backtrace'] = queue_options[:backtrace] if queue_options[:backtrace]
|
69
|
+
args
|
70
|
+
end
|
63
71
|
end
|
64
72
|
end
|
65
73
|
end
|
data/lib/backgrounder/version.rb
CHANGED
@@ -12,7 +12,8 @@ module CarrierWave
|
|
12
12
|
|
13
13
|
def self.configure
|
14
14
|
yield self
|
15
|
-
|
15
|
+
case @backend
|
16
|
+
when :sidekiq
|
16
17
|
::CarrierWave::Workers::ProcessAsset.class_eval do
|
17
18
|
require 'sidekiq'
|
18
19
|
include ::Sidekiq::Worker
|
@@ -21,36 +22,19 @@ module CarrierWave
|
|
21
22
|
require 'sidekiq'
|
22
23
|
include ::Sidekiq::Worker
|
23
24
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
if defined?(Rails)
|
31
|
-
module CarrierWave
|
32
|
-
module Backgrounder
|
33
|
-
class Railtie < Rails::Railtie
|
34
|
-
|
35
|
-
initializer "carrierwave_backgrounder.active_record" do
|
36
|
-
ActiveSupport.on_load :active_record do
|
37
|
-
require 'backgrounder/orm/activemodel'
|
38
|
-
::ActiveRecord::Base.extend CarrierWave::Backgrounder::ORM::ActiveModel
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
initializer "carrierwave_backgrounder.data_mapper", :before =>"data_mapper.add_to_prepare" do
|
43
|
-
require 'backgrounder/orm/data_mapper' if defined?(DataMapper)
|
25
|
+
when :sucker_punch
|
26
|
+
::CarrierWave::Workers::ProcessAsset.class_eval do
|
27
|
+
require 'sucker_punch'
|
28
|
+
include ::SuckerPunch::Worker
|
44
29
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
require 'backgrounder/orm/activemodel'
|
49
|
-
::Mongoid::Document::ClassMethods.send(:include, ::CarrierWave::Backgrounder::ORM::ActiveModel)
|
50
|
-
end
|
30
|
+
::CarrierWave::Workers::StoreAsset.class_eval do
|
31
|
+
require 'sucker_punch'
|
32
|
+
include ::SuckerPunch::Worker
|
51
33
|
end
|
52
|
-
|
53
34
|
end
|
54
35
|
end
|
36
|
+
|
55
37
|
end
|
56
38
|
end
|
39
|
+
|
40
|
+
require 'backgrounder/railtie' if defined?(Rails)
|
@@ -9,6 +9,7 @@ describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
9
9
|
def self.after_commit(method, opts); nil; end
|
10
10
|
def avatar_changed?; nil; end
|
11
11
|
def remote_avatar_url; OpenStruct.new(:present? => true); end
|
12
|
+
def remove_avatar?; false; end
|
12
13
|
def previous_changes; {}; end
|
13
14
|
end
|
14
15
|
|
@@ -11,8 +11,9 @@ describe Support::Backends do
|
|
11
11
|
|
12
12
|
describe 'setting backend' do
|
13
13
|
it 'using #backend=' do
|
14
|
-
|
15
|
-
|
14
|
+
expect {
|
15
|
+
mock_module.backend = :delayed_job
|
16
|
+
}.to raise_error(NoMethodError)
|
16
17
|
end
|
17
18
|
|
18
19
|
it 'using #backend' do
|
@@ -123,6 +124,28 @@ describe Support::Backends do
|
|
123
124
|
end
|
124
125
|
end
|
125
126
|
|
127
|
+
context 'sucker_punch' do
|
128
|
+
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
129
|
+
let(:mock_sp) { mock('SuckerPunch')}
|
130
|
+
|
131
|
+
before do
|
132
|
+
mock_sp.expects(:async).returns(mock_sp)
|
133
|
+
mock_sp.expects(:perform).with('FakeClass', 1, :image)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'sets the queue to :carrierwave by default' do
|
137
|
+
SuckerPunch::Queue.expects(:[]).with(:carrierwave).returns(mock_sp)
|
138
|
+
mock_module.backend :sucker_punch
|
139
|
+
mock_module.enqueue_for_backend(*args)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'sets the queue to backend :queue option' do
|
143
|
+
SuckerPunch::Queue.expects(:[]).with(:awesome_queue).returns(mock_sp)
|
144
|
+
mock_module.backend :sucker_punch, :queue => :awesome_queue
|
145
|
+
mock_module.enqueue_for_backend(*args)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
126
149
|
context 'qu' do
|
127
150
|
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
128
151
|
before do
|
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.1
|
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-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/backgrounder/orm/activemodel.rb
|
95
95
|
- lib/backgrounder/orm/base.rb
|
96
96
|
- lib/backgrounder/orm/data_mapper.rb
|
97
|
+
- lib/backgrounder/railtie.rb
|
97
98
|
- lib/backgrounder/support/backends.rb
|
98
99
|
- lib/backgrounder/version.rb
|
99
100
|
- lib/backgrounder/workers.rb
|
@@ -127,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
128
|
version: '0'
|
128
129
|
segments:
|
129
130
|
- 0
|
130
|
-
hash:
|
131
|
+
hash: 1936252162021597709
|
131
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
133
|
none: false
|
133
134
|
requirements:
|
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
137
|
version: '0'
|
137
138
|
segments:
|
138
139
|
- 0
|
139
|
-
hash:
|
140
|
+
hash: 1936252162021597709
|
140
141
|
requirements: []
|
141
142
|
rubyforge_project:
|
142
143
|
rubygems_version: 1.8.24
|