joumae 0.2.4 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/joumae/command.rb +50 -19
- data/lib/joumae/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23733726cd6b1593664ad3f5d45a4feddf9ddb76
|
4
|
+
data.tar.gz: 0d83a648e087441e265f42e7848a11c65a0fe9d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a137e7ae4d8af192ed4aa1e8c9ca5814e0352fb9189cf53c7f0ffd5ff0c40e949782e69a154f52f317ce707f53900600d8eae7fc6b8cd06932ea70e8ab83e44
|
7
|
+
data.tar.gz: 7b97fda2118205053ea627e2bbabde5990c465a745a472806aaa9cad15414dc846ee4c678f71205ae973dc87443b66a8e3b7e2fb49ce5738c648f3dd49d12f79
|
data/Gemfile.lock
CHANGED
data/lib/joumae/command.rb
CHANGED
@@ -29,12 +29,7 @@ module Joumae
|
|
29
29
|
def run!
|
30
30
|
status = Joumae::Transaction.run!(resource_name: @resource_name, client: @client) do
|
31
31
|
Open3.popen3(cmd) do |i, o, e, w|
|
32
|
-
|
33
|
-
redirect(STDIN => i)
|
34
|
-
end
|
35
|
-
i.close
|
36
|
-
|
37
|
-
redirect(o => STDOUT, e => STDERR)
|
32
|
+
redirect(STDIN => i, o => STDOUT, e => STDERR)
|
38
33
|
|
39
34
|
debug w.value
|
40
35
|
|
@@ -47,25 +42,61 @@ module Joumae
|
|
47
42
|
private
|
48
43
|
|
49
44
|
def redirect(mapping)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
45
|
+
inputs = mapping.keys
|
46
|
+
ios_ready_for_eof_check = []
|
47
|
+
|
48
|
+
debug "Joumae::Command#redirect: mapping: " + mapping.inspect
|
49
|
+
|
50
|
+
# Calling IO#eof against an IO which is not `select`ed previous blocks the current thread.
|
51
|
+
# So you can't do something like :
|
52
|
+
# until inputs.all?(&:eof) do
|
53
|
+
# Or:
|
54
|
+
# until (inputs - [STDIN]).all?(&:eof) do
|
55
|
+
until inputs.empty? || (inputs.size == 1 && inputs.first == STDIN) do
|
56
|
+
debug 'starting `select`'
|
57
|
+
|
58
|
+
readable_inputs, = IO.select(inputs, [], [])
|
59
|
+
ios_ready_for_eof_check = readable_inputs
|
60
|
+
|
61
|
+
debug 'finished `select`'
|
62
|
+
|
63
|
+
# We can safely call `eof` without blocking against previously selected IOs.
|
64
|
+
debug 'starting eof check'
|
65
|
+
ios_ready_for_eof_check.select(&:eof).each do |src|
|
66
|
+
debug "Stopping redirection from an IO in EOF: " + src.inspect
|
67
|
+
# `select`ing an IO which has reached EOF blocks forever.
|
68
|
+
# So you have to delete such IO from the array of IOs to `select`.
|
69
|
+
inputs.delete src
|
70
|
+
|
71
|
+
# You must close the child process' STDIN immeditely after the parent's STDIN reached EOF,
|
72
|
+
# or some kinds of child processes never exit.
|
73
|
+
# e.g.) echo foobar | joumae run -- cat
|
74
|
+
# After the `echo` finished outputting `foobar`, you have to tell `cat` about that or `cat` will wait for more inputs forever.
|
75
|
+
mapping[src].close if src == STDIN
|
76
|
+
end
|
56
77
|
|
57
|
-
|
78
|
+
break if inputs.empty? || (inputs.size == 1 && inputs.first == STDIN)
|
58
79
|
|
59
|
-
|
80
|
+
readable_inputs.each do |input|
|
60
81
|
begin
|
61
|
-
data =
|
62
|
-
|
63
|
-
|
64
|
-
|
82
|
+
data = input.read_nonblock(1024)
|
83
|
+
output = mapping[input]
|
84
|
+
output.write(data)
|
85
|
+
output.flush
|
65
86
|
rescue EOFError => e
|
66
|
-
debug e
|
87
|
+
debug "Reached EOF: #{e}"
|
88
|
+
inputs.delete input
|
89
|
+
rescue Errno::EPIPE => e
|
90
|
+
# How to produce this error:
|
91
|
+
# 1. Run the command:
|
92
|
+
# cat | bin/joumae run --resource-name test -- bundle exec ruby -v
|
93
|
+
# 2. Press Enter several times
|
94
|
+
debug "Handled error: #{e}: io: #{input.inspect}"
|
95
|
+
inputs.delete input
|
67
96
|
end
|
68
97
|
end
|
98
|
+
|
99
|
+
ios_ready_for_eof_check = inputs & readable_inputs
|
69
100
|
end
|
70
101
|
end
|
71
102
|
|
data/lib/joumae/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joumae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke KUOKA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|