shotgunner 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/{shotgunner.rb → shotgunner/parallel.rb} +23 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85cd18f2f681df1a5c63ecdeb70d2f42d6bf60a65b47f1468c72a744e5043fed
|
4
|
+
data.tar.gz: c9cc0ebe0eb0e484096701cbe1eb4f0ba9c2e5b70eefc8c68e2d4f504b31d3ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e74d52c2a3a5917fea3ab9e84c3204673bf08281348391a77db3ee6dc886699b95427bbbbcf002c82344ad7770da6d1660c42f7da1510453ea400e4abf92d2c4
|
7
|
+
data.tar.gz: e326e3b6d6511db5b4cd81a2f7b6abbe4e844beba787ec73b589f47b2cf6724bee06a803efb4439319a11e11950dc3b504130bd1b99db4cc87f808cc3f1dfead
|
@@ -9,26 +9,41 @@ module Shotgunner
|
|
9
9
|
|
10
10
|
module InstanceMethods
|
11
11
|
def run(options = {}, &block)
|
12
|
-
self.class.
|
12
|
+
self.class.run(options, &block)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
17
17
|
def run(options = {}, &block)
|
18
|
-
mutex =
|
19
|
-
|
20
|
-
tasks
|
21
|
-
|
22
|
-
call_results = []
|
18
|
+
call_results, mutex, tasks, threads = initiate(options)
|
19
|
+
|
20
|
+
validate_params(tasks, threads)
|
21
|
+
|
23
22
|
threads.times.map do
|
24
23
|
Thread.new(tasks, call_results) do |tasks, call_results|
|
25
24
|
while (task = mutex.synchronize { tasks.pop })
|
26
25
|
call_result = yield(task)
|
27
|
-
mutex.synchronize { call_results
|
26
|
+
mutex.synchronize { call_results[task] = call_result }
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end.each(&:join)
|
31
|
-
|
30
|
+
|
31
|
+
call_results.map{|v| v[1]}
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def validate_params(tasks, threads)
|
37
|
+
raise ArgumentError, 'There is no tasks array defined!' if tasks.empty?
|
38
|
+
raise ArgumentError, 'Invalid threads number, please select number from 1..100' unless threads&.between?(1, 100)
|
39
|
+
end
|
40
|
+
|
41
|
+
def initiate(options)
|
42
|
+
mutex = Mutex.new
|
43
|
+
threads = options[:threads] || 4
|
44
|
+
tasks = options[:tasks]&.dup || []
|
45
|
+
call_results = Hash[tasks.map { |x| [x, nil] }]
|
46
|
+
[call_results, mutex, tasks, threads]
|
32
47
|
end
|
33
48
|
end
|
34
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shotgunner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Saltykov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -16,7 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- lib/shotgunner.rb
|
19
|
+
- lib/shotgunner/parallel.rb
|
20
20
|
homepage: https://github.com/nucleom42/shotgunner
|
21
21
|
licenses: []
|
22
22
|
metadata: {}
|