saviour 0.6.6 → 0.6.7

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
2
  SHA256:
3
- metadata.gz: e01220554bae6d136bace3b491f366aa5e5f8a8e6b853b1d19f5fe2ee194f7ac
4
- data.tar.gz: cce3bf80da5aad0f7056422f9e30d9595f5c2b597f899346f09f0b615e0c5ce3
3
+ metadata.gz: 43509e7e421eab9a8b45159d62c58513dbcb894b0ccecbd96a70cc0a29db74a6
4
+ data.tar.gz: 91b2eb4cf47dbac1b642c5ccc198ae0040ea0e81ef993c580e894065f1e58ecf
5
5
  SHA512:
6
- metadata.gz: 0b9b2682ffb7d3584853b3cb3ceca37cbae5f95a9802eabbe5d3df80a5de79810dbb3f26e5cb29fdfcf2acb128a9cd8d9f459458e0dc43bf93c47ec1274af303
7
- data.tar.gz: 0a94d1526dcbb231bb27feb1b47cd913dd668ee127e6ce41961a67d2cd14ff646a7f52b856d5dc2b2758c1e3ca59b12473f2a8b9227c5c1078d17cd860a90bbe
6
+ metadata.gz: e4a1fb654e3290d827236f115ebfd93e2f6d4994e57d022dd473f41436365de36182e689d20526cea2c9bb113dd6b558901da5deda945f526242ab2e78e7c633
7
+ data.tar.gz: 8f3f81305ceb56195d67eb2a6700a5f05bb3e4567c892a983fe845689c952864497e2bd29c47a4256a88a6f003527855952d2ed78e6edc7cff80d66adacca7b0
@@ -2,8 +2,9 @@ language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.5.0
6
- - 2.6.0
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.1
7
8
 
8
9
  gemfile:
9
10
  - gemfiles/5.1.gemfile
@@ -17,7 +17,8 @@ require 'saviour/db_helpers'
17
17
 
18
18
  require 'tempfile'
19
19
  require 'fileutils'
20
- require 'concurrent/future'
20
+ require 'concurrent/edge/throttle'
21
+ require 'concurrent/edge/lock_free_queue'
21
22
 
22
23
  require 'active_support/dependencies'
23
24
 
@@ -1,5 +1,7 @@
1
1
  module Saviour
2
2
  class LifeCycle
3
+ SHOULD_USE_INTERLOCK = defined?(Rails)
4
+
3
5
  class FileCreator
4
6
  def initialize(current_path, file, column, connection)
5
7
  @file = file
@@ -84,26 +86,19 @@ module Saviour
84
86
 
85
87
  def delete!
86
88
  DbHelpers.run_after_commit do
87
- pool = Concurrent::FixedThreadPool.new(Saviour::Config.concurrent_workers)
89
+ pool = Concurrent::Throttle.new Saviour::Config.concurrent_workers
88
90
 
89
91
  futures = attached_files.map do |column|
90
- Concurrent::Future.execute(executor: pool) {
91
- file = @model.send(column)
92
+ pool.future(@model.send(column)) do |file|
92
93
  path = file.persisted_path
93
94
  file.uploader.storage.delete(path) if path
94
95
  file.delete
95
- }
96
+ end
96
97
  end
97
98
 
98
99
  ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
99
- futures.each do |future|
100
- future.value
101
- raise(future.reason) if future.rejected?
102
- end
100
+ futures.each(&:value!)
103
101
  end
104
-
105
- pool.shutdown
106
- pool.wait_for_termination
107
102
  end
108
103
  end
109
104
 
@@ -131,35 +126,26 @@ module Saviour
131
126
  )
132
127
  end.compact
133
128
 
134
- pool = Concurrent::FixedThreadPool.new(Saviour::Config.concurrent_workers)
129
+ pool = Concurrent::Throttle.new Saviour::Config.concurrent_workers
135
130
 
136
131
  futures = uploaders.map { |uploader|
137
- Concurrent::Future.execute(executor: pool) {
138
- if defined?(Rails) && Rails::VERSION::MAJOR < 6
139
- Rails.application.executor.wrap { uploader.upload }
132
+ pool.future(uploader) { |given_uploader|
133
+ if SHOULD_USE_INTERLOCK
134
+ Rails.application.executor.wrap { given_uploader.upload }
140
135
  else
141
- uploader.upload
136
+ given_uploader.upload
142
137
  end
143
138
  }
144
139
  }
145
140
 
146
- work = -> {
147
- futures.map do |x|
148
- x.value.tap do
149
- raise(x.reason) if x.rejected?
150
- end
151
- end.compact
152
- }
141
+ work = -> { futures.map(&:value!).compact }
153
142
 
154
- result = if defined?(Rails) && Rails::VERSION::MAJOR < 6
143
+ result = if SHOULD_USE_INTERLOCK
155
144
  ActiveSupport::Dependencies.interlock.permit_concurrent_loads(&work)
156
145
  else
157
146
  work.call
158
147
  end
159
148
 
160
- pool.shutdown
161
- pool.wait_for_termination
162
-
163
149
  attrs = result.to_h
164
150
 
165
151
  uploaders.map(&:uploader).select { |x| x.class.after_upload_hooks.any? }.each do |uploader|
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.7"
3
3
  end
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.add_dependency "activerecord", ">= 5.1"
19
19
  spec.add_dependency "activesupport", ">= 5.1"
20
20
  spec.add_dependency "concurrent-ruby", ">= 1.0.5"
21
+ spec.add_dependency "concurrent-ruby-edge", ">= 0.6.0"
21
22
 
22
23
  spec.add_development_dependency "bundler"
23
24
  spec.add_development_dependency "rspec"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saviour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Campos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-16 00:00:00.000000000 Z
11
+ date: 2020-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.0.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: concurrent-ruby-edge
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -241,8 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
255
  - !ruby/object:Gem::Version
242
256
  version: '0'
243
257
  requirements: []
244
- rubyforge_project:
245
- rubygems_version: 2.7.6
258
+ rubygems_version: 3.0.3
246
259
  signing_key:
247
260
  specification_version: 4
248
261
  summary: File storage handler following active record model lifecycle