saviour 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/saviour.rb +2 -0
- data/lib/saviour/life_cycle.rb +17 -7
- data/lib/saviour/version.rb +1 -1
- data/spec/feature/concurrent_processors_spec.rb +43 -33
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d30fa955590994c40acee59df17db7840c20d772afd8532e772813f53cdf9588
|
4
|
+
data.tar.gz: 37f60dce478723b85d08ba25e971497b9a20829fab51c0d6f46e2422661cfa5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0055e48b2d02bc40270c32ddf797089c0ef4c7fcfc1d29ecae04b2abd6a72ce952b2faf319bed50619b5497eab337001e950edb2c4b0a06a478dce7fefbc8941
|
7
|
+
data.tar.gz: bb9bd3648caaa9fc1c379f374f7c97f5e131916ba3ffa600f691db28ae90853afed59432b86f359b0f1d93064d3efb683f2fe4c7f0f58dc8d118992569d764c6
|
data/lib/saviour.rb
CHANGED
data/lib/saviour/life_cycle.rb
CHANGED
@@ -115,17 +115,27 @@ module Saviour
|
|
115
115
|
end.compact
|
116
116
|
|
117
117
|
pool = Concurrent::FixedThreadPool.new(Saviour::Config.concurrent_workers)
|
118
|
-
futures = uploaders.map { |uploader|
|
118
|
+
futures = uploaders.map { |uploader|
|
119
|
+
Concurrent::Future.execute(executor: pool) {
|
120
|
+
if defined?(Rails)
|
121
|
+
Rails.application.executor.wrap { uploader.upload }
|
122
|
+
else
|
123
|
+
uploader.upload
|
124
|
+
end
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
result = ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
129
|
+
futures.map do |x|
|
130
|
+
x.value.tap do
|
131
|
+
raise(x.reason) if x.rejected?
|
132
|
+
end
|
133
|
+
end.compact
|
134
|
+
end
|
119
135
|
|
120
136
|
pool.shutdown
|
121
137
|
pool.wait_for_termination
|
122
138
|
|
123
|
-
result = futures.map do |x|
|
124
|
-
x.value.tap do
|
125
|
-
raise(x.reason) if x.rejected?
|
126
|
-
end
|
127
|
-
end.compact
|
128
|
-
|
129
139
|
attrs = result.to_h
|
130
140
|
|
131
141
|
uploaders.map(&:uploader).select { |x| x.class.after_upload_hooks.any? }.each do |uploader|
|
data/lib/saviour/version.rb
CHANGED
@@ -10,15 +10,29 @@ describe "concurrent processors" do
|
|
10
10
|
store_dir { "/store/dir" }
|
11
11
|
|
12
12
|
process_with_file do |file, filename|
|
13
|
+
stash(attached_as => Time.now.to_f)
|
13
14
|
sleep WAIT_TIME
|
14
15
|
|
15
16
|
[file, filename]
|
16
17
|
end
|
18
|
+
|
19
|
+
after_upload do |stash|
|
20
|
+
model.times = model.times.merge(stash)
|
21
|
+
end
|
17
22
|
}
|
18
23
|
}
|
19
24
|
|
20
25
|
let(:klass) {
|
21
|
-
klass = Class.new(Test) {
|
26
|
+
klass = Class.new(Test) {
|
27
|
+
include Saviour::Model
|
28
|
+
|
29
|
+
attr_accessor :times
|
30
|
+
|
31
|
+
def initialize(*)
|
32
|
+
super
|
33
|
+
@times = {}
|
34
|
+
end
|
35
|
+
}
|
22
36
|
klass.attach_file :file, uploader
|
23
37
|
klass.attach_file :file_thumb, uploader
|
24
38
|
klass.attach_file :file_thumb_2, uploader
|
@@ -32,15 +46,13 @@ describe "concurrent processors" do
|
|
32
46
|
|
33
47
|
Saviour::Config.concurrent_workers = 4
|
34
48
|
|
35
|
-
t0 = Time.now
|
36
49
|
a.update_attributes! file: Saviour::StringSource.new("contents", "file.txt"),
|
37
50
|
file_thumb: Saviour::StringSource.new("contents", "file_2.txt"),
|
38
51
|
file_thumb_2: Saviour::StringSource.new("contents", "file_3.txt"),
|
39
52
|
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
40
53
|
|
41
|
-
|
42
|
-
expect(
|
43
|
-
expect(diff).to be < WAIT_TIME * 4
|
54
|
+
start_times = a.times.values.sort
|
55
|
+
expect((start_times[0] - start_times[-1]).abs).to be_within(0.1).of(0)
|
44
56
|
end
|
45
57
|
|
46
58
|
it 'works in serial with 1 worker' do
|
@@ -48,13 +60,13 @@ describe "concurrent processors" do
|
|
48
60
|
|
49
61
|
Saviour::Config.concurrent_workers = 1
|
50
62
|
|
51
|
-
t0 = Time.now
|
52
63
|
a.update_attributes! file: Saviour::StringSource.new("contents", "file.txt"),
|
53
64
|
file_thumb: Saviour::StringSource.new("contents", "file_2.txt"),
|
54
65
|
file_thumb_2: Saviour::StringSource.new("contents", "file_3.txt"),
|
55
66
|
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
56
67
|
|
57
|
-
|
68
|
+
start_times = a.times.values.sort
|
69
|
+
expect((start_times[0] - start_times[-1]).abs).to be > WAIT_TIME * 3
|
58
70
|
end
|
59
71
|
|
60
72
|
it 'concurrency can be adjusted' do
|
@@ -62,15 +74,15 @@ describe "concurrent processors" do
|
|
62
74
|
|
63
75
|
Saviour::Config.concurrent_workers = 2
|
64
76
|
|
65
|
-
t0 = Time.now
|
66
77
|
a.update_attributes! file: Saviour::StringSource.new("contents", "file.txt"),
|
67
78
|
file_thumb: Saviour::StringSource.new("contents", "file_2.txt"),
|
68
79
|
file_thumb_2: Saviour::StringSource.new("contents", "file_3.txt"),
|
69
80
|
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
70
81
|
|
71
|
-
|
72
|
-
expect(
|
73
|
-
expect(
|
82
|
+
start_times = a.times.values.sort
|
83
|
+
expect((start_times[0] - start_times[1]).abs).to be_within(0.1).of(0)
|
84
|
+
expect((start_times[2] - start_times[3]).abs).to be_within(0.1).of(0)
|
85
|
+
expect((start_times[0] - start_times[-1]).abs).to be > WAIT_TIME
|
74
86
|
end
|
75
87
|
end
|
76
88
|
|
@@ -78,41 +90,39 @@ describe "concurrent processors" do
|
|
78
90
|
it 'works concurrently with 4 workers' do
|
79
91
|
Saviour::Config.concurrent_workers = 4
|
80
92
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
93
|
+
a = klass.create! file: Saviour::StringSource.new("contents", "file.txt"),
|
94
|
+
file_thumb: Saviour::StringSource.new("contents", "file_2.txt"),
|
95
|
+
file_thumb_2: Saviour::StringSource.new("contents", "file_3.txt"),
|
96
|
+
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
86
97
|
|
87
|
-
|
88
|
-
expect(
|
89
|
-
expect(diff).to be < WAIT_TIME * 4
|
98
|
+
start_times = a.times.values.sort
|
99
|
+
expect((start_times[0] - start_times[-1]).abs).to be_within(0.1).of(0)
|
90
100
|
end
|
91
101
|
|
92
102
|
it 'works in serial with 1 worker' do
|
93
103
|
Saviour::Config.concurrent_workers = 1
|
94
104
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
105
|
+
a = klass.create! file: Saviour::StringSource.new("contents", "file.txt"),
|
106
|
+
file_thumb: Saviour::StringSource.new("contents", "file_2.txt"),
|
107
|
+
file_thumb_2: Saviour::StringSource.new("contents", "file_3.txt"),
|
108
|
+
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
100
109
|
|
101
|
-
|
110
|
+
start_times = a.times.values.sort
|
111
|
+
expect((start_times[0] - start_times[-1]).abs).to be > WAIT_TIME * 3
|
102
112
|
end
|
103
113
|
|
104
114
|
it 'concurrency can be adjusted' do
|
105
115
|
Saviour::Config.concurrent_workers = 2
|
106
116
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
117
|
+
a = klass.create! file: Saviour::StringSource.new("contents", "file.txt"),
|
118
|
+
file_thumb: Saviour::StringSource.new("contents", "file_2.txt"),
|
119
|
+
file_thumb_2: Saviour::StringSource.new("contents", "file_3.txt"),
|
120
|
+
file_thumb_3: Saviour::StringSource.new("contents", "file_4.txt")
|
112
121
|
|
113
|
-
|
114
|
-
expect(
|
115
|
-
expect(
|
122
|
+
start_times = a.times.values.sort
|
123
|
+
expect((start_times[0] - start_times[1]).abs).to be_within(0.1).of(0)
|
124
|
+
expect((start_times[2] - start_times[3]).abs).to be_within(0.1).of(0)
|
125
|
+
expect((start_times[0] - start_times[-1]).abs).to be > WAIT_TIME
|
116
126
|
end
|
117
127
|
end
|
118
128
|
end
|
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.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Campos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|