in-parallel 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: a79b9831824dee514b121f2911693c825c8bda13
4
- data.tar.gz: 630845c4f1c5d2f22b83cb6e2a7467118371bf91
3
+ metadata.gz: 40ad2577f36e54c5587299b0d14d6ef77b3c4e29
4
+ data.tar.gz: 17952b28df96dbc02a21deefee815f4d01419aac
5
5
  SHA512:
6
- metadata.gz: 97a010bf1fdd61118c873ef60f807b65da112edb9867aa5c68823713cdd0d7e3bf1dae8cf8dc4fc3cc36d47b2f9f1722048106ed21f3cce486ebc1fdf2274ce8
7
- data.tar.gz: 14c0e06a6e09f135e56656cc5496cbd6bb15a7613b3964acd306c33ab8259de8062f125675607b851a1ea4a8323c64fc32c46e940f4405212adca2b6275d1afb
6
+ metadata.gz: 7a9d29ad97abb4d9ca344c8d4d5d3a8fdf795e51e45c656cb2aadc65cbb3f86998be65066c723408bff7d0e7d89072a069b871bc300f1741f8c65e058c35ed3c
7
+ data.tar.gz: f0b0fb02ef1ffbf220fee8aef49fdb71b93ea028747dd15a297d85cbb6b760aa9ea6d508d7f69265c8d683c7b1441dc944ed76f36e9af4d983af073d376ea649
@@ -1,3 +1,3 @@
1
1
  module InParallel
2
- VERSION = Version = '0.1.5'
2
+ VERSION = Version = '0.1.6'
3
3
  end
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 = nil, binding = nil)
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|
@@ -1,18 +1,23 @@
1
- # Monkey patching Enumerable to make it easy to do any .each in parallel
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
- def each_in_parallel(method_sym=nil, &block)
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
- method_sym ||= "#{caller_locations[0]}"
14
+ identifier ||= "#{caller_locations[0]}"
10
15
  each do |item|
11
- out = InParallelExecutor._execute_in_parallel(method_sym) {block.call(item)}
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 InParallel.wait_for_processes
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in-parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - samwoods1