prcs 0.2.0 → 0.3.0
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/Gemfile.lock +1 -1
- data/lib/prcs.rb +28 -10
- data/lib/prcs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7fa54dc731ecef77d0dea7c842729eb9e969df2044876104f587675ecdf8b6e
|
4
|
+
data.tar.gz: ba6d8533b334085cfefa0bd2cce873cd5d936cc52bd8793a7b57a683c1390041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcc20dc8393d858b918b0566b2888518cf3e7ec43e3f9fa398b65c95fe259fb8dd2ca30eaadff163a0add5601d83af90cdd5e6e2843f254dd69f6b34caf0e684
|
7
|
+
data.tar.gz: 86b9c1f7152680b06e33da3a09d529ca699f9cd08263cb2cbe7a6ee5ccd60bd24d458e76582805af371d1ad9e28125e9c46d328e91b05dacf2d42fc53cecb292
|
data/Gemfile.lock
CHANGED
data/lib/prcs.rb
CHANGED
@@ -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.
|
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
|
-
|
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
|
-
}
|
114
|
+
}
|
101
115
|
end
|
102
116
|
|
103
117
|
def stderr_queue
|
104
|
-
|
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
|
-
}
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
def stdin
|
129
|
+
@process.io.stdin
|
112
130
|
end
|
113
131
|
|
114
132
|
def stdout
|
data/lib/prcs/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: childprocess
|