carrierwave_backgrounder 1.0.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-ci.yml +43 -0
- data/CHANGELOG.md +6 -1
- data/README.md +5 -12
- data/carrierwave_backgrounder.gemspec +4 -1
- data/lib/backgrounder/version.rb +1 -1
- data/lib/backgrounder/workers/base.rb +2 -1
- data/lib/backgrounder/workers/process_asset_mixin.rb +3 -0
- data/lib/carrierwave_backgrounder.rb +7 -4
- data/lib/generators/carrierwave_backgrounder/templates/config/initializers/carrierwave_backgrounder.rb +3 -0
- data/spec/backgrounder/orm/activemodel_spec.rb +1 -2
- data/spec/integrations/process_in_background_spec.rb +29 -0
- data/spec/integrations/store_in_background_spec.rb +34 -0
- data/spec/support/dummy_app/app/uploaders/avatar_uploader.rb +1 -0
- data/spec/support/dummy_app/config/initializers/carrierwave_backgrounder.rb +3 -0
- metadata +4 -4
- data/.travis.yml +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1e007beb6c4d7bdd9d12f197d3dd1ef9a1fd0db2cff176c91bf556167311c916
|
|
4
|
+
data.tar.gz: d6d3ffca8551ea931c9788c02b1b6aa73ace34274229152c5816ed871f9e50a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2186ebdc16e2e3dd6dc76d5998ba79b23903caaf956d18fa403228f75e636b145bb3b7a0b0d0ef078e3c9530bb868dbae20d3b83beddd0a4bfa9a168c351b667
|
|
7
|
+
data.tar.gz: 35cc9df51de365463319a0d4cdd9df204ecb44105f5975d37cbaf1a1e3aff68335082fbf3f83ac98975722e9012447dc93429c039603d44def6856fe1c2cab7d
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Ruby CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
ruby: ['3.2', '3.4', 'ruby-head']
|
|
16
|
+
queue_adapter: ['sidekiq', 'active_job']
|
|
17
|
+
continue-on-error: ${{ matrix.ruby == 'ruby-head' }}
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install ImageMagick
|
|
22
|
+
run: sudo apt-get update && sudo apt-get install -y imagemagick
|
|
23
|
+
|
|
24
|
+
- name: Set up Ruby
|
|
25
|
+
uses: ruby/setup-ruby@v1
|
|
26
|
+
with:
|
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
|
28
|
+
bundler-cache: true
|
|
29
|
+
|
|
30
|
+
- name: Update RubyGems
|
|
31
|
+
run: yes | gem update --system --force
|
|
32
|
+
|
|
33
|
+
- name: Install Bundler
|
|
34
|
+
run: gem install bundler
|
|
35
|
+
|
|
36
|
+
- name: Set QUEUE_ADAPTER env
|
|
37
|
+
run: echo "QUEUE_ADAPTER=${{ matrix.queue_adapter }}" >> $GITHUB_ENV
|
|
38
|
+
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
run: bundle install --jobs 4 --retry 3
|
|
41
|
+
|
|
42
|
+
- name: Run tests
|
|
43
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
## 1.1.0
|
|
2
|
+
|
|
3
|
+
### enhancements
|
|
4
|
+
* Suppress NotFoundError if a record gets deleted before it is processed. This is configurable and defaults to true. [lardawge]
|
|
5
|
+
|
|
1
6
|
## 1.0.3
|
|
2
7
|
|
|
3
8
|
### enhancements
|
|
4
|
-
* Add support for Rails 8.0 [
|
|
9
|
+
* Add support for Rails 8.0 [damisul]
|
|
5
10
|
|
|
6
11
|
## 1.0.2
|
|
7
12
|
|
data/README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# CarrierWave Backgrounder
|
|
2
2
|
|
|
3
|
-
[](https://github.com/lardawge/carrierwave_backgrounder/actions/workflows/ruby-ci.yml)
|
|
4
|
+
[](https://qlty.sh/gh/lardawge/projects/carrierwave_backgrounder)
|
|
5
|
+
---
|
|
6
|
+
NOTICE: Version 1.1.0 contains a change in behavior from previous version. When a record is deleted before the job is picked up, it will no longer raise an error. Prior to this change, when using `process_in_background`, if a record was missing, an error was raised. Some users might have relied on that. By default, this will no longer happen. If you want to maintain that behavior, you must set the `suppress_record_not_found_errors` configuration to `false`. This will raise a RecordNotFound error.
|
|
10
7
|
|
|
8
|
+
---
|
|
11
9
|
I am a fan of CarrierWave. That being said, I don't like tying up requests waiting for images to process.
|
|
12
10
|
|
|
13
11
|
This gem addresses that by offloading processing or storaging/processing to a background task.
|
|
@@ -190,11 +188,6 @@ class MyActiveJobWorker < ::CarrierWave::Workers::ActiveJob::StoreAsset
|
|
|
190
188
|
end
|
|
191
189
|
```
|
|
192
190
|
|
|
193
|
-
### Testing with Rspec
|
|
194
|
-
We use the after_commit hook when using active_record. This creates a problem when testing with Rspec because after_commit never gets fired
|
|
195
|
-
if you're using transactional fixtures. One solution to the problem is to use the [TestAfterCommit gem](https://github.com/grosser/test_after_commit).
|
|
196
|
-
There are various other solutions in which case google is your friend.
|
|
197
|
-
|
|
198
191
|
## License
|
|
199
192
|
|
|
200
193
|
Copyright (c) 2011 Larry Sprock
|
|
@@ -6,17 +6,20 @@ Gem::Specification.new do |s|
|
|
|
6
6
|
s.name = "carrierwave_backgrounder"
|
|
7
7
|
s.version = CarrierWave::Backgrounder::VERSION
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
|
+
|
|
9
10
|
s.authors = ["Larry Sprock"]
|
|
10
11
|
s.email = ["larry@lucidbleu.com"]
|
|
11
12
|
s.homepage = "https://github.com/lardawge/carrierwave_backgrounder"
|
|
12
13
|
s.licenses = ["MIT"]
|
|
13
|
-
s.summary = %q{Offload CarrierWave's image processing and storage to a background process using
|
|
14
|
+
s.summary = %q{Offload CarrierWave's image processing and storage to a background process using ActiveJob or Sidekiq.}
|
|
14
15
|
|
|
15
16
|
s.files = `git ls-files`.split("\n")
|
|
16
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
17
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
18
19
|
s.require_paths = ["lib"]
|
|
19
20
|
|
|
21
|
+
s.required_ruby_version = '>= 3.0'
|
|
22
|
+
|
|
20
23
|
s.add_dependency "carrierwave", ["> 2.0", "< 4.0"]
|
|
21
24
|
s.add_dependency "rails", ["> 6.0", "< 8.1"]
|
|
22
25
|
|
data/lib/backgrounder/version.rb
CHANGED
|
@@ -14,12 +14,13 @@ module CarrierWave
|
|
|
14
14
|
set_args(*args) if args.present?
|
|
15
15
|
self.record = constantized_resource.find id
|
|
16
16
|
rescue *not_found_errors
|
|
17
|
+
raise not_found_errors.first unless CarrierWave::Backgrounder.suppress_not_found_errors
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
private
|
|
20
21
|
|
|
21
22
|
def not_found_errors
|
|
22
|
-
[].tap do |errors|
|
|
23
|
+
@not_found_errors ||= [].tap do |errors|
|
|
23
24
|
errors << ::ActiveRecord::RecordNotFound if defined?(::ActiveRecord)
|
|
24
25
|
errors << ::Mongoid::Errors::DocumentNotFound if defined?(::Mongoid)
|
|
25
26
|
end
|
|
@@ -9,17 +9,17 @@ module CarrierWave
|
|
|
9
9
|
include Support::Backends
|
|
10
10
|
|
|
11
11
|
class << self
|
|
12
|
-
attr_reader :worker_klass
|
|
12
|
+
attr_reader :worker_klass, :suppress_not_found_errors
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def self.configure
|
|
16
16
|
yield self
|
|
17
17
|
|
|
18
|
+
@suppress_not_found_errors ||= true
|
|
19
|
+
|
|
18
20
|
case backend
|
|
19
21
|
when :active_job
|
|
20
22
|
@worker_klass = 'CarrierWave::Workers::ActiveJob'
|
|
21
|
-
|
|
22
|
-
require 'active_job'
|
|
23
23
|
require 'backgrounder/workers/active_job/process_asset'
|
|
24
24
|
require 'backgrounder/workers/active_job/store_asset'
|
|
25
25
|
|
|
@@ -34,7 +34,6 @@ module CarrierWave
|
|
|
34
34
|
when :sidekiq
|
|
35
35
|
@worker_klass = 'CarrierWave::Workers'
|
|
36
36
|
|
|
37
|
-
require 'sidekiq'
|
|
38
37
|
::CarrierWave::Workers::ProcessAsset.class_eval do
|
|
39
38
|
include ::Sidekiq::Worker
|
|
40
39
|
end
|
|
@@ -43,6 +42,10 @@ module CarrierWave
|
|
|
43
42
|
end
|
|
44
43
|
end
|
|
45
44
|
end
|
|
45
|
+
|
|
46
|
+
def self.suppress_record_not_found_errors(surpress_errors = true)
|
|
47
|
+
@suppress_not_found_errors = surpress_errors
|
|
48
|
+
end
|
|
46
49
|
end
|
|
47
50
|
end
|
|
48
51
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
CarrierWave::Backgrounder.configure do |c|
|
|
2
2
|
c.backend :active_job, queue: :carrierwave
|
|
3
3
|
# c.backend :sidekiq, queue: :carrierwave
|
|
4
|
+
|
|
5
|
+
## Uncomment if you would like a NotFoundError raised if a record is deleted before processing
|
|
6
|
+
# c.suppress_record_not_found_errors false
|
|
4
7
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'ostruct'
|
|
3
2
|
require 'backgrounder/orm/activemodel'
|
|
4
3
|
|
|
5
4
|
RSpec.describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
@@ -9,7 +8,7 @@ RSpec.describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
|
9
8
|
def self.after_commit(method, opts); nil; end
|
|
10
9
|
def avatar_changed?; nil; end
|
|
11
10
|
def avatar_present?; true; end
|
|
12
|
-
def remote_avatar_url;
|
|
11
|
+
def remote_avatar_url; true; end
|
|
13
12
|
def remove_avatar?; false; end
|
|
14
13
|
def previous_changes; {}; end
|
|
15
14
|
def self.uploader_options; {}; end
|
|
@@ -22,6 +22,35 @@ RSpec.describe '::process_in_background', clear_images: true do
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
context 'when a record gets deleted before it is processed' do
|
|
26
|
+
context 'and suppress_record_not_found_errors is set to true' do
|
|
27
|
+
before do
|
|
28
|
+
admin.update(avatar: load_file('test-1.jpg'))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'does not raise an error' do
|
|
32
|
+
admin.delete
|
|
33
|
+
expect { process_latest_sidekiq_job }.not_to raise_error
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'and suppress_record_not_found_errors is set to false' do
|
|
38
|
+
before do
|
|
39
|
+
admin.update(avatar: load_file('test-1.jpg'))
|
|
40
|
+
CarrierWave::Backgrounder.suppress_record_not_found_errors(false)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
after do
|
|
44
|
+
CarrierWave::Backgrounder.suppress_record_not_found_errors(true)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'raises an error' do
|
|
48
|
+
admin.delete
|
|
49
|
+
expect { process_latest_sidekiq_job }.to raise_error(ActiveRecord::RecordNotFound)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
25
54
|
context 'when processing the worker' do
|
|
26
55
|
before do
|
|
27
56
|
admin.update(avatar: load_file('test-1.jpg'))
|
|
@@ -31,6 +31,11 @@ RSpec.describe '::store_in_background', clear_images: true do
|
|
|
31
31
|
user.reload
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
it 'processes the original image' do
|
|
35
|
+
image = MiniMagick::Image.open(user.avatar.path)
|
|
36
|
+
expect(image.width).to eql(1960)
|
|
37
|
+
end
|
|
38
|
+
|
|
34
39
|
it 'creates the versions' do
|
|
35
40
|
version_paths = user.avatar.versions.keys.map { |key| user.avatar.send(key).current_path }
|
|
36
41
|
version_paths.each { |path| expect(File.exist?(path)).to be(true) }
|
|
@@ -63,6 +68,35 @@ RSpec.describe '::store_in_background', clear_images: true do
|
|
|
63
68
|
end
|
|
64
69
|
end
|
|
65
70
|
|
|
71
|
+
context 'when a record gets deleted before it is processed' do
|
|
72
|
+
context 'and suppress_record_not_found_errors is set to true' do
|
|
73
|
+
before do
|
|
74
|
+
user.update(avatar: load_file('test-1.jpg'))
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'does not raise an error' do
|
|
78
|
+
user.delete
|
|
79
|
+
expect { process_latest_sidekiq_job }.not_to raise_error
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context 'and suppress_record_not_found_errors is set to false' do
|
|
84
|
+
before do
|
|
85
|
+
user.update(avatar: load_file('test-1.jpg'))
|
|
86
|
+
CarrierWave::Backgrounder.suppress_record_not_found_errors(false)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
after do
|
|
90
|
+
CarrierWave::Backgrounder.suppress_record_not_found_errors(true)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'raises an error' do
|
|
94
|
+
user.delete
|
|
95
|
+
expect { process_latest_sidekiq_job }.to raise_error(ActiveRecord::RecordNotFound)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
66
100
|
context 'when setting a column for removal' do
|
|
67
101
|
let!(:user) {
|
|
68
102
|
Sidekiq::Testing.inline! 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: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Larry Sprock
|
|
@@ -139,9 +139,9 @@ executables: []
|
|
|
139
139
|
extensions: []
|
|
140
140
|
extra_rdoc_files: []
|
|
141
141
|
files:
|
|
142
|
+
- ".github/workflows/ruby-ci.yml"
|
|
142
143
|
- ".gitignore"
|
|
143
144
|
- ".rspec"
|
|
144
|
-
- ".travis.yml"
|
|
145
145
|
- CHANGELOG.md
|
|
146
146
|
- Gemfile
|
|
147
147
|
- README.md
|
|
@@ -242,7 +242,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
242
242
|
requirements:
|
|
243
243
|
- - ">="
|
|
244
244
|
- !ruby/object:Gem::Version
|
|
245
|
-
version: '0'
|
|
245
|
+
version: '3.0'
|
|
246
246
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
247
|
requirements:
|
|
248
248
|
- - ">="
|
|
@@ -252,7 +252,7 @@ requirements: []
|
|
|
252
252
|
rubygems_version: 3.6.9
|
|
253
253
|
specification_version: 4
|
|
254
254
|
summary: Offload CarrierWave's image processing and storage to a background process
|
|
255
|
-
using
|
|
255
|
+
using ActiveJob or Sidekiq.
|
|
256
256
|
test_files:
|
|
257
257
|
- spec/backgrounder/orm/activemodel_spec.rb
|
|
258
258
|
- spec/backgrounder/orm/base_spec.rb
|
data/.travis.yml
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
|
|
3
|
-
rvm:
|
|
4
|
-
- 2.7
|
|
5
|
-
- 3.0
|
|
6
|
-
- 3.1
|
|
7
|
-
- 3.2
|
|
8
|
-
- ruby-head
|
|
9
|
-
|
|
10
|
-
env:
|
|
11
|
-
- QUEUE_ADAPTER='sidekiq'
|
|
12
|
-
- QUEUE_ADAPTER='active_job'
|
|
13
|
-
|
|
14
|
-
before_install:
|
|
15
|
-
- yes | gem update --system --force
|
|
16
|
-
- gem install bundler
|
|
17
|
-
|
|
18
|
-
matrix:
|
|
19
|
-
allow_failures:
|
|
20
|
-
- rvm: ruby-head
|