carrierwave_backgrounder 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ea7ccc20dfbd12f0d5ca49a22aed4df13af757fe
4
- data.tar.gz: 9483744462a3c7de8ec21c01c033fe5c7722c1b7
2
+ SHA256:
3
+ metadata.gz: c08d7bdb01034545507f0ef13305aa12764e2771148c4ddc22f1291fbba8f7f9
4
+ data.tar.gz: 21d4f4a1cd200c5b05f9b967d4fda436e7d11752ba6fb6307f619a7b32ae1924
5
5
  SHA512:
6
- metadata.gz: a9ccbcd89a9f510723a6f512197cc3595ffe4bfa00a9ea21c3c1e6b2530fee1901b47670d1bf0e6e44427d40fd71c83064eab553f09c7e1d0b75cb3283d0291e
7
- data.tar.gz: 437d6b11a142e94ae83699672299bf1a3da800846f4465aa557027bb4026970619ee425b6fc63ca7e5e11687a9dfe417c08213ddbc9300ed826a8361a95f6e61
6
+ metadata.gz: 683938ec5318b2727ae40e177a717fc6135f479f397cbdd39e0b3639a70ff3508ef98406ced8fd203b6d34d4017a84d2a2eab64f164d69bd8d24c64e2ff1786c
7
+ data.tar.gz: 44b9e651e679fa450dfbe9620e58e5472c0be9bc20bd7f4ce29894de28c30c7f6d5c04f7dd9aa56fc4277bd8d0a3ff0205aa287fb31439e8bfaa5d6158ccbe0b
data/.travis.yml CHANGED
@@ -1,10 +1,16 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
6
8
  - ruby-head
7
9
 
10
+ before_install:
11
+ - yes | gem update --system --force
12
+ - gem install bundler
13
+
8
14
  matrix:
9
15
  allow_failures:
10
16
  - rvm: ruby-head
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ ## 0.4.3
3
+
4
+ ### enhancements
5
+ * [#307] Add support for Sidekiq 7 [holstvoogd]
6
+ * [#278] Add sidekiq queue config [IlkhamGaysin]
7
+
2
8
  ## 0.4.2
3
9
 
4
10
  ### enhancements
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/lardawge/carrierwave_backgrounder.png)](http://travis-ci.org/lardawge/carrierwave_backgrounder)
4
4
  [![Code Climate](https://codeclimate.com/github/lardawge/carrierwave_backgrounder.png)](https://codeclimate.com/github/lardawge/carrierwave_backgrounder)
5
- [![Still Maintained](http://stillmaintained.com/lardawge/carrierwave_backgrounder.png)](http://stillmaintained.com/lardawge/carrierwave_backgrounder)
6
5
 
7
6
  I like CarrierWave. That being said, I don't like tying up app instances waiting for images to process.
8
7
 
@@ -55,6 +54,14 @@ CarrierWave::Backgrounder.configure do |c|
55
54
  end
56
55
  ```
57
56
 
57
+ **IMPORTANT FOR SIDEKIQ BACKEND** - Custom queue should be defined inside the Sidekiq configuration otherwise jobs won't be processed:
58
+
59
+ ```yml
60
+ :queues:
61
+ - [awesome_queue, 1]
62
+ - default
63
+ ```
64
+
58
65
  In your CarrierWave uploader file:
59
66
 
60
67
  ```ruby
@@ -135,9 +142,36 @@ class MyParanoidWorker < ::CarrierWave::Workers::ProcessAsset
135
142
  # other hooks you might care about
136
143
  end
137
144
  ```
145
+
146
+ ### ActiveJob
147
+ Use overriden worker that inherits from ActiveJob::Base and includes relevant worker mixin:
148
+ ```ruby
149
+ class MyActiveJobWorker < ActiveJob::Base
150
+ include ::CarrierWave::Workers::ProcessAssetMixin
151
+ # ... or include ::CarrierWave::Workers::StoreAssetMixin
152
+
153
+ after_perform do
154
+ # your code here
155
+ end
156
+
157
+ # Sometimes job gets performed before the file is uploaded and ready.
158
+ # You can define how to handle that case by overriding `when_not_ready` method
159
+ # (by default it does nothing)
160
+ def when_not_ready
161
+ retry_job
162
+ end
163
+ end
164
+ ```
165
+ Don't forget to set `active_job` as a backend in the config:
166
+ ```ruby
167
+ CarrierWave::Backgrounder.configure do |c|
168
+ c.backend :active_job, queue: :carrierwave
169
+ end
170
+ ```
171
+
138
172
  ### Testing with Rspec
139
173
  We use the after_commit hook when using active_record. This creates a problem when testing with Rspec because after_commit never gets fired
140
- if you're using trasactional fixtures. One solution to the problem is to use the [TestAfterCommit gem](https://github.com/grosser/test_after_commit).
174
+ if you're using transactional fixtures. One solution to the problem is to use the [TestAfterCommit gem](https://github.com/grosser/test_after_commit).
141
175
  There are various other solutions in which case google is your friend.
142
176
 
143
177
  ### Uploaders mounted on mongoid embedded documents
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency "carrierwave", ["~> 0.5"]
20
+ s.add_dependency "carrierwave", [">= 0.5", "< 2.2"]
21
21
 
22
- s.add_development_dependency "rspec", ["~> 3.1.0"]
22
+ s.add_development_dependency "rspec", ["~> 3.10.0"]
23
23
  s.add_development_dependency "rake"
24
24
  end
@@ -82,7 +82,7 @@ module CarrierWave
82
82
 
83
83
  def write_#{column}_identifier
84
84
  super and return if process_#{column}_upload
85
- self.#{column}_tmp = _mounter(:#{column}).cache_name if _mounter(:#{column}).cache_name
85
+ self.#{column}_tmp = #{column}_cache if #{column}_cache
86
86
  end
87
87
 
88
88
  def store_#{column}!
@@ -26,7 +26,7 @@ module CarrierWave
26
26
 
27
27
  def write_#{column}_identifier
28
28
  super and return if process_#{column}_upload
29
- self.#{column}_tmp = _mounter(:#{column}).cache_name
29
+ self.#{column}_tmp = #{column}_cache
30
30
  end
31
31
  RUBY
32
32
  end
@@ -22,6 +22,10 @@ module CarrierWave
22
22
 
23
23
  private
24
24
 
25
+ def enqueue_active_job(worker, *args)
26
+ worker.perform_later(*args.map(&:to_s))
27
+ end
28
+
25
29
  def enqueue_delayed_job(worker, *args)
26
30
  worker_args = {}
27
31
  if ::Delayed::Job.new.respond_to?(:queue)
@@ -44,7 +48,7 @@ module CarrierWave
44
48
 
45
49
  def enqueue_sidekiq(worker, *args)
46
50
  override_queue_name = worker.sidekiq_options['queue'] == 'default' || worker.sidekiq_options['queue'].nil?
47
- args = sidekiq_queue_options(override_queue_name, 'class' => worker, 'args' => args)
51
+ args = sidekiq_queue_options(override_queue_name, 'class' => worker, 'args' => args.map(&:to_s))
48
52
  worker.client_push(args)
49
53
  end
50
54
 
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module Backgrounder
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
@@ -1,14 +1,18 @@
1
+ # encoding: utf-8
1
2
  module CarrierWave
2
3
  module Workers
3
- class Base < Struct.new(:klass, :id, :column)
4
4
 
5
- def self.perform(*args)
6
- new(*args).perform
5
+ module Base
6
+ attr_accessor :klass, :id, :column, :record
7
+
8
+ def initialize(*args)
9
+ super(*args) unless self.class.superclass == Object
10
+ set_args(*args) if args.present?
7
11
  end
8
12
 
9
13
  def perform(*args)
10
14
  set_args(*args) if args.present?
11
- constantized_resource.find id
15
+ self.record = constantized_resource.find id
12
16
  rescue *not_found_errors
13
17
  end
14
18
 
@@ -29,6 +33,10 @@ module CarrierWave
29
33
  klass.is_a?(String) ? klass.constantize : klass
30
34
  end
31
35
 
32
- end
33
- end
34
- end
36
+ def when_not_ready
37
+ end
38
+
39
+ end # Base
40
+
41
+ end # Workers
42
+ end # CarrierWave
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ module CarrierWave
3
+ module Workers
4
+
5
+ module ClassMethods
6
+
7
+ def perform(*args)
8
+ new(*args).perform
9
+ end
10
+
11
+ end # ClassMethods
12
+
13
+ end # Workers
14
+ end # Backgrounder
@@ -2,19 +2,8 @@
2
2
  module CarrierWave
3
3
  module Workers
4
4
 
5
- class ProcessAsset < Base
6
-
7
- def perform(*args)
8
- record = super(*args)
9
-
10
- if record && record.send(:"#{column}").present?
11
- record.send(:"process_#{column}_upload=", true)
12
- if record.send(:"#{column}").recreate_versions! && record.respond_to?(:"#{column}_processing")
13
- record.update_attribute :"#{column}_processing", false
14
- end
15
- end
16
- end
17
-
5
+ class ProcessAsset
6
+ include CarrierWave::Workers::ProcessAssetMixin
18
7
  end # ProcessAsset
19
8
 
20
9
  end # Workers
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ module CarrierWave
3
+ module Workers
4
+
5
+ module ProcessAssetMixin
6
+ include CarrierWave::Workers::Base
7
+
8
+ def self.included(base)
9
+ base.extend CarrierWave::Workers::ClassMethods
10
+ end
11
+
12
+ def perform(*args)
13
+ record = super(*args)
14
+
15
+ if record && record.send(:"#{column}").present?
16
+ record.send(:"process_#{column}_upload=", true)
17
+ if record.send(:"#{column}").recreate_versions! && record.respond_to?(:"#{column}_processing")
18
+ record.update_attribute :"#{column}_processing", false
19
+ end
20
+ else
21
+ when_not_ready
22
+ end
23
+ end
24
+
25
+ end # ProcessAssetMixin
26
+
27
+ end # Workers
28
+ end # Backgrounder
@@ -2,32 +2,8 @@
2
2
  module CarrierWave
3
3
  module Workers
4
4
 
5
- class StoreAsset < Base
6
- attr_reader :cache_path, :tmp_directory
7
-
8
- def perform(*args)
9
- record = super(*args)
10
-
11
- if record && record.send(:"#{column}_tmp")
12
- store_directories(record)
13
- record.send :"process_#{column}_upload=", true
14
- record.send :"#{column}_tmp=", nil
15
- record.send :"#{column}_processing=", false if record.respond_to?(:"#{column}_processing")
16
- File.open(cache_path) { |f| record.send :"#{column}=", f }
17
- if record.save!
18
- FileUtils.rm_r(tmp_directory, :force => true)
19
- end
20
- end
21
- end
22
-
23
- private
24
-
25
- def store_directories(record)
26
- asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp")
27
- cache_directory = File.expand_path(asset.cache_dir, asset.root)
28
- @cache_path = File.join(cache_directory, asset_tmp)
29
- @tmp_directory = File.join(cache_directory, asset_tmp.split("/").first)
30
- end
5
+ class StoreAsset
6
+ include CarrierWave::Workers::StoreAssetMixin
31
7
  end # StoreAsset
32
8
 
33
9
  end # Workers
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ module CarrierWave
3
+ module Workers
4
+
5
+ module StoreAssetMixin
6
+ include CarrierWave::Workers::Base
7
+
8
+ def self.included(base)
9
+ base.extend CarrierWave::Workers::ClassMethods
10
+ end
11
+
12
+ attr_reader :cache_path, :tmp_directory
13
+
14
+ def perform(*args)
15
+ record = super(*args)
16
+
17
+ if record && record.send(:"#{column}_tmp")
18
+ store_directories(record)
19
+ record.send :"process_#{column}_upload=", true
20
+ record.send :"#{column}_tmp=", nil
21
+ record.send :"#{column}_processing=", false if record.respond_to?(:"#{column}_processing")
22
+ File.open(cache_path) { |f| record.send :"#{column}=", f }
23
+ if record.save!
24
+ FileUtils.rm_r(tmp_directory, :force => true)
25
+ end
26
+ else
27
+ when_not_ready
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def store_directories(record)
34
+ asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp")
35
+ cache_directory = File.expand_path(asset.cache_dir, asset.root)
36
+ @cache_path = File.join(cache_directory, asset_tmp)
37
+ @tmp_directory = File.join(cache_directory, asset_tmp.split("/").first)
38
+ end
39
+
40
+ end # StoreAssetMixin
41
+
42
+ end # Workers
43
+ end # Backgrounder
@@ -1,3 +1,6 @@
1
1
  require 'backgrounder/workers/base'
2
+ require 'backgrounder/workers/class_methods'
3
+ require 'backgrounder/workers/process_asset_mixin'
4
+ require 'backgrounder/workers/store_asset_mixin'
2
5
  require 'backgrounder/workers/process_asset'
3
6
  require 'backgrounder/workers/store_asset'
@@ -1,5 +1,6 @@
1
1
  CarrierWave::Backgrounder.configure do |c|
2
2
  c.backend :delayed_job, queue: :carrierwave
3
+ # c.backend :active_job, queue: :carrierwave
3
4
  # c.backend :resque, queue: :carrierwave
4
5
  # c.backend :sidekiq, queue: :carrierwave
5
6
  # c.backend :girl_friday, queue: :carrierwave
@@ -31,6 +31,16 @@ module CarrierWave::Backgrounder
31
31
  describe '#enqueue_for_backend' do
32
32
  let!(:worker) { MockWorker.new('FakeClass', 1, :image) }
33
33
 
34
+ context 'active_job' do
35
+ let(:args) { ['FakeClass', 1, :image] }
36
+
37
+ it 'invokes perform_later with string arguments' do
38
+ expect(MockWorker).to receive(:perform_later).with('FakeClass', '1', 'image')
39
+ mock_module.backend :active_job
40
+ mock_module.enqueue_for_backend(MockWorker, *args)
41
+ end
42
+ end
43
+
34
44
  context 'delayed_job' do
35
45
  before do
36
46
  @mock_worker = Class.new do
@@ -112,7 +122,7 @@ module CarrierWave::Backgrounder
112
122
  let(:args) { ['FakeClass', 1, :image] }
113
123
 
114
124
  it 'invokes client_push on the class with passed args' do
115
- expect(MockSidekiqWorker).to receive(:client_push).with({ 'class' => MockSidekiqWorker, 'args' => args })
125
+ expect(MockSidekiqWorker).to receive(:client_push).with({ 'class' => MockSidekiqWorker, 'args' => args.map(&:to_s) })
116
126
  mock_module.backend :sidekiq
117
127
  mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
118
128
  end
@@ -122,7 +132,7 @@ module CarrierWave::Backgrounder
122
132
  'retry' => false,
123
133
  'timeout' => 60,
124
134
  'queue' => :awesome_queue,
125
- 'args' => args })
135
+ 'args' => args.map(&:to_s) })
126
136
  options = {:retry => false, :timeout => 60, :queue => :awesome_queue}
127
137
  mock_module.backend :sidekiq, options
128
138
  mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
@@ -132,7 +142,7 @@ module CarrierWave::Backgrounder
132
142
  expect(MockNamedSidekiqWorker).to receive(:client_push).with({ 'class' => MockNamedSidekiqWorker,
133
143
  'retry' => false,
134
144
  'timeout' => 60,
135
- 'args' => args })
145
+ 'args' => args.map(&:to_s) })
136
146
  options = {:retry => false, :timeout => 60}
137
147
  mock_module.backend :sidekiq, options
138
148
  mock_module.enqueue_for_backend(MockNamedSidekiqWorker, *args)
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave_backgrounder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Larry Sprock
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2023-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.5'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.5'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rspec
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: 3.1.0
39
+ version: 3.10.0
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: 3.1.0
46
+ version: 3.10.0
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rake
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +58,7 @@ dependencies:
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
55
- description:
61
+ description:
56
62
  email:
57
63
  - larry@lucidbleu.com
58
64
  executables: []
@@ -76,8 +82,11 @@ files:
76
82
  - lib/backgrounder/version.rb
77
83
  - lib/backgrounder/workers.rb
78
84
  - lib/backgrounder/workers/base.rb
85
+ - lib/backgrounder/workers/class_methods.rb
79
86
  - lib/backgrounder/workers/process_asset.rb
87
+ - lib/backgrounder/workers/process_asset_mixin.rb
80
88
  - lib/backgrounder/workers/store_asset.rb
89
+ - lib/backgrounder/workers/store_asset_mixin.rb
81
90
  - lib/carrierwave_backgrounder.rb
82
91
  - lib/generators/carrierwave_backgrounder/USAGE
83
92
  - lib/generators/carrierwave_backgrounder/install_generator.rb
@@ -95,7 +104,7 @@ homepage: https://github.com/lardawge/carrierwave_backgrounder
95
104
  licenses:
96
105
  - MIT
97
106
  metadata: {}
98
- post_install_message:
107
+ post_install_message:
99
108
  rdoc_options: []
100
109
  require_paths:
101
110
  - lib
@@ -110,9 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
119
  - !ruby/object:Gem::Version
111
120
  version: '0'
112
121
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.2.2
115
- signing_key:
122
+ rubygems_version: 3.1.6
123
+ signing_key:
116
124
  specification_version: 4
117
125
  summary: Offload CarrierWave's image processing and storage to a background process
118
126
  using Delayed Job, Resque, Sidekiq, Qu, Queue Classic or Girl Friday