prcs 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/prcs.rb +28 -10
  4. data/lib/prcs/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 077573c7fbd76fa760861e115d6897484a287cc07fedc31d96f042c6506de005
4
- data.tar.gz: 0ec469f6a34a5aa7c95c7a8630df1da23c95f316e0fc481ede1a2bbf1073592b
3
+ metadata.gz: f7fa54dc731ecef77d0dea7c842729eb9e969df2044876104f587675ecdf8b6e
4
+ data.tar.gz: ba6d8533b334085cfefa0bd2cce873cd5d936cc52bd8793a7b57a683c1390041
5
5
  SHA512:
6
- metadata.gz: ade5ea2adac2f69a436ca4002d897df3a372dddb5d75b3e0092c12fb47a0089d9ba3e6f40303ec72aba8bb23c205277170bb5b3333e4eaf4e9c4547143f16fbe
7
- data.tar.gz: 07c203c333c4b9b1e0f8fdd199171a5b7a6752a28e525ff9ffa05b4456337f586442b3cee3402ef8a0fb8813b32ddc0f21927538d26332ce418756ecce5553e4
6
+ metadata.gz: bcc20dc8393d858b918b0566b2888518cf3e7ec43e3f9fa398b65c95fe259fb8dd2ca30eaadff163a0add5601d83af90cdd5e6e2843f254dd69f6b34caf0e684
7
+ data.tar.gz: 86b9c1f7152680b06e33da3a09d529ca699f9cd08263cb2cbe7a6ee5ccd60bd24d458e76582805af371d1ad9e28125e9c46d328e91b05dacf2d42fc53cecb292
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prcs (0.1.0)
4
+ prcs (0.3.0)
5
5
  childprocess (~> 3.0, >= 3.0.0)
6
6
  ffi (~> 1.12)
7
7
 
@@ -7,11 +7,13 @@ module PRCS
7
7
  class Error < StandardError; end
8
8
 
9
9
  class Runner
10
+ attr_reader :command
11
+
10
12
  def initialize(command)
11
13
  @command = command
12
14
  @process = nil
13
- @stdout = ""
14
- @stderr = ""
15
+ @stdout = nil
16
+ @stderr = nil
15
17
 
16
18
  @external_queues = {}.tap do |it|
17
19
  it[:stdout] = Queue.new
@@ -20,13 +22,13 @@ module PRCS
20
22
  @logcollectors = {}
21
23
  end
22
24
 
23
- def run!
25
+ def run!(stdin = nil)
24
26
  stdout_pipe, stdout_wr = IO.pipe
25
27
  stderr_pipe, stderr_wr = IO.pipe
26
28
 
27
29
  ChildProcess.posix_spawn = true
28
30
  @process = ChildProcess.build(*@command)
29
- @process.leader = true
31
+ @process.duplex = true if stdin
30
32
  @process.io.stdout = stdout_wr
31
33
  @process.io.stderr = stderr_wr
32
34
 
@@ -35,6 +37,11 @@ module PRCS
35
37
  stdout_wr.close
36
38
  stderr_wr.close
37
39
 
40
+ if stdin
41
+ @process.io.stdin.write(stdin)
42
+ @process.io.stdin.close
43
+ end
44
+
38
45
  @logcollectors[:stdout] = Thread.new(stdout_pipe) do |pipe|
39
46
  Thread.current[:running] = true
40
47
  Thread.current[:log] = ""
@@ -44,9 +51,9 @@ module PRCS
44
51
  output = pipe.readline_nonblock
45
52
  @external_queues[:stdout] << output
46
53
  Thread.current[:log] << output
54
+ sleep(0.1)
47
55
  rescue IO::EAGAINWaitReadable, EOFError
48
56
  end
49
- sleep(1)
50
57
  end
51
58
  end
52
59
 
@@ -59,15 +66,22 @@ module PRCS
59
66
  output = pipe.readline_nonblock
60
67
  @external_queues[:stderr] << output
61
68
  Thread.current[:log] << output
69
+ sleep(0.1)
62
70
  rescue IO::EAGAINWaitReadable, EOFError
63
71
  end
64
- sleep(1)
65
72
  end
66
73
  end
67
74
 
68
75
  self
69
76
  end
70
77
 
78
+ def run_and_wait!
79
+ self.run!
80
+ @process.wait
81
+
82
+ self
83
+ end
84
+
71
85
  def kill!(timeout = 15)
72
86
  @logcollectors.values.each do |collector_thread|
73
87
  collector_thread[:running] = false
@@ -90,25 +104,29 @@ module PRCS
90
104
  end
91
105
 
92
106
  def stdout_queue
93
- [].tap { |it|
107
+ "".tap { |it|
94
108
  begin
95
109
  while(true)
96
110
  it << @external_queues[:stdout].pop(true)
97
111
  end
98
112
  rescue ThreadError
99
113
  end
100
- }.join
114
+ }
101
115
  end
102
116
 
103
117
  def stderr_queue
104
- [].tap { |it|
118
+ "".tap { |it|
105
119
  begin
106
120
  while(true)
107
121
  it << @external_queues[:stderr].pop(true)
108
122
  end
109
123
  rescue ThreadError
110
124
  end
111
- }.join
125
+ }
126
+ end
127
+
128
+ def stdin
129
+ @process.io.stdin
112
130
  end
113
131
 
114
132
  def stdout
@@ -1,3 +1,3 @@
1
1
  module PRCS
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prcs
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
  - Kasper Grubbe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-20 00:00:00.000000000 Z
11
+ date: 2020-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: childprocess