multi_process 0.2.0 → 0.3.0

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: 12b6e61ecec6390d6c06f1ddbdc1a9288f65c0c1
4
- data.tar.gz: b09e0b1587f578428daa05bb4dacb1fe11324dc9
3
+ metadata.gz: b36af9795f93f2669e9dd7a511a3ac1b1f9bde68
4
+ data.tar.gz: 3ef8504b7074aed6326f5163ebf8a10c81b55541
5
5
  SHA512:
6
- metadata.gz: 8e3e41b5665d57220412d203735786c7ae506386824cd3c6b00830692414c81e7dfdf4d697321ebffccb7d420e661018e45efe19e94712ceaad91bd38a8d7ef7
7
- data.tar.gz: c57700b68cc35c3a5f63268d70ed10a89d04069e7e87f08418c8513e30c9571716b1a53699713cd83ee61846030997e2547251ab05b93b5ebf6814641fbe561c
6
+ metadata.gz: 49607ae3364368750c8d2492363b5503636c25b044fbe69febe07d65dc7b01c3d928a9fd394450e6bcafa20fbe839e7331c61b373d2e2ed8226d6d4ebdeb064a
7
+ data.tar.gz: 69f544973eee8b3cbe1191d5eba27836e289023a460d151d9f52808b198c0c69c66062b1832516e39f99567b5b88ce5ea97bfb58d9b4a86d9348f2621439569d
data/lib/multi_process.rb CHANGED
@@ -7,6 +7,7 @@ module MultiProcess
7
7
  require 'multi_process/group'
8
8
  require 'multi_process/receiver'
9
9
  require 'multi_process/nil_receiver'
10
+ require 'multi_process/string_receiver'
10
11
  require 'multi_process/logger'
11
12
 
12
13
  require 'multi_process/process'
@@ -38,6 +38,10 @@ module MultiProcess
38
38
  pipe.gets
39
39
  end
40
40
 
41
+ def collapse?
42
+ @opts[:collapse].nil? || @opts[:collapse]
43
+ end
44
+
41
45
  private
42
46
  def output(process, line, opts = {})
43
47
  @mutex.synchronize do
@@ -50,7 +54,7 @@ module MultiProcess
50
54
  end
51
55
 
52
56
  io = opts[:io] || @out
53
- if @last_name == name
57
+ if @last_name == name && collapse?
54
58
  io.print " #{' ' * name.length} #{opts[:delimiter]} "
55
59
  else
56
60
  io.print " #{name} #{opts[:delimiter]} "
@@ -29,7 +29,7 @@ module MultiProcess
29
29
  @env = opts[:env] if Hash === opts[:env]
30
30
  @env_clean = opts[:clean_env].nil? ? true : !!opts[:clean_env]
31
31
 
32
- self.receiver = MultiProcess::Logger.global
32
+ self.receiver = opts[:receiver] || MultiProcess::Logger.global
33
33
 
34
34
  self.dir = Dir.pwd
35
35
  self.dir = opts[:dir].to_s if opts[:dir]
@@ -18,12 +18,12 @@ module MultiProcess
18
18
  loop do
19
19
  io = IO.select(@readers.keys, nil, nil, 0.1)
20
20
  (io.nil? ? [] : io.first).each do |reader|
21
+ op = @readers[reader]
22
+
21
23
  if reader.eof?
22
- op = @readers[reader]
23
24
  @readers.delete_if { |key, value| key == reader }
24
25
  removed op[:process], op[:name]
25
26
  else
26
- op = @readers[reader]
27
27
  received op[:process], op[:name], read(reader)
28
28
  end
29
29
  end
@@ -0,0 +1,17 @@
1
+ module MultiProcess
2
+
3
+ # Receiver implementation storing process output
4
+ # in string.
5
+ #
6
+ class StringReceiver < Receiver
7
+
8
+ def received(process, name, message)
9
+ get(name) << message
10
+ end
11
+
12
+ def get(name)
13
+ @strings ||= Hash.new
14
+ @strings[name.to_s] ||= String.new
15
+ end
16
+ end
17
+ end
@@ -1,7 +1,7 @@
1
1
  module MultiProcess
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 2
4
+ MINOR = 3
5
5
  PATCH = 0
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
data/spec/files/env.rb ADDED
@@ -0,0 +1,5 @@
1
+
2
+ $stdout.puts "ENV: #{ENV[ARGV[0]]}"
3
+ $stdout.sync
4
+
5
+ sleep 1
@@ -5,7 +5,7 @@ describe MultiProcess do
5
5
  it 'should run processes' do
6
6
  reader, writer = IO.pipe
7
7
 
8
- logger = MultiProcess::Logger.new writer
8
+ logger = MultiProcess::Logger.new writer, collapse: false
9
9
  group = MultiProcess::Group.new receiver: logger
10
10
  group << MultiProcess::Process.new(%w(ruby spec/files/test.rb A), title: 'rubyA')
11
11
  group << MultiProcess::Process.new(%w(ruby spec/files/test.rb B), title: 'rubyB')
@@ -54,4 +54,12 @@ describe MultiProcess do
54
54
  group.run
55
55
  expect(Time.now - start).to be_within(0.3).of(2)
56
56
  end
57
+
58
+ it 'should env processes' do
59
+ receiver = MultiProcess::StringReceiver.new
60
+ process = MultiProcess::Process.new(%w(ruby spec/files/env.rb TEST), env: {'TEST' => "abc"}, receiver: receiver)
61
+ process.run
62
+
63
+ expect(receiver.get(:out)).to eq "ENV: abc\n"
64
+ end
57
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_process
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
@@ -72,8 +72,10 @@ files:
72
72
  - lib/multi_process/process/bundle_exec.rb
73
73
  - lib/multi_process/process/rails.rb
74
74
  - lib/multi_process/receiver.rb
75
+ - lib/multi_process/string_receiver.rb
75
76
  - lib/multi_process/version.rb
76
77
  - multi_process.gemspec
78
+ - spec/files/env.rb
77
79
  - spec/files/sleep.rb
78
80
  - spec/files/test.rb
79
81
  - spec/multi_process_spec.rb
@@ -103,6 +105,7 @@ signing_key:
103
105
  specification_version: 4
104
106
  summary: Handle multiple child processes.
105
107
  test_files:
108
+ - spec/files/env.rb
106
109
  - spec/files/sleep.rb
107
110
  - spec/files/test.rb
108
111
  - spec/multi_process_spec.rb