in-parallel 0.1.5 → 0.1.6
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/in_parallel/version.rb +1 -1
- data/lib/in_parallel.rb +1 -1
- data/lib/parallel_enumerable.rb +14 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40ad2577f36e54c5587299b0d14d6ef77b3c4e29
|
4
|
+
data.tar.gz: 17952b28df96dbc02a21deefee815f4d01419aac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a9d29ad97abb4d9ca344c8d4d5d3a8fdf795e51e45c656cb2aadc65cbb3f86998be65066c723408bff7d0e7d89072a069b871bc300f1741f8c65e058c35ed3c
|
7
|
+
data.tar.gz: f0b0fb02ef1ffbf220fee8aef49fdb71b93ea028747dd15a297d85cbb6b760aa9ea6d508d7f69265c8d683c7b1441dc944ed76f36e9af4d983af073d376ea649
|
data/in_parallel/version.rb
CHANGED
data/lib/in_parallel.rb
CHANGED
@@ -89,7 +89,7 @@ module InParallel
|
|
89
89
|
|
90
90
|
# Waits for all processes to complete and logs STDOUT and STDERR in chunks from any processes
|
91
91
|
# that were triggered from this Parallel class
|
92
|
-
def self.wait_for_processes(proxy =
|
92
|
+
def self.wait_for_processes(proxy = self, binding = nil)
|
93
93
|
trap(:INT) do
|
94
94
|
puts "Warning, recieved interrupt. Processing child results and exiting."
|
95
95
|
@@process_infos.each { |process_info|
|
data/lib/parallel_enumerable.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
|
-
#
|
2
|
-
# Example - Will run puppet agent -t on each agent in parallel:
|
3
|
-
# agents.each_in_parallel { |agent|
|
4
|
-
# on agent, 'puppet agent -t'
|
5
|
-
# }
|
1
|
+
# Extending Enumerable to make it easy to do any .each in parallel
|
6
2
|
module Enumerable
|
7
|
-
|
3
|
+
# Executes each iteration of the block in parallel
|
4
|
+
# Example - Will execute each iteration in a separate process, in parallel,
|
5
|
+
# log STDOUT per process, and return an array of results.
|
6
|
+
# my_array = [1,2,3]
|
7
|
+
# my_array.each_in_parallel { |int|
|
8
|
+
# my_method(int)
|
9
|
+
# }
|
10
|
+
# @param [String] identifier - Optional identifier for logging purposes only. Will use the block location by default.
|
11
|
+
# @return [Array<Object>] results - the return value of each block execution.
|
12
|
+
def each_in_parallel(identifier=nil, &block)
|
8
13
|
if Process.respond_to?(:fork) && count > 1
|
9
|
-
|
14
|
+
identifier ||= "#{caller_locations[0]}"
|
10
15
|
each do |item|
|
11
|
-
out =
|
16
|
+
out = InParallel._execute_in_parallel(method_sym) {block.call(item)}
|
12
17
|
puts "'each_in_parallel' forked process for '#{method_sym}' - PID = '#{out[:pid]}'\n"
|
13
18
|
end
|
14
19
|
# return the array of values, no need to look up from the map.
|
15
|
-
return
|
20
|
+
return ::InParallelExecutor.wait_for_processes(nil, block.binding)
|
16
21
|
end
|
17
22
|
puts 'Warning: Fork is not supported on this OS, executing block normally' unless Process.respond_to? :fork
|
18
23
|
block.call
|