run_tasks 3.0.0 → 3.1.1
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/src/run/core.rb +1 -7
- data/src/run/helper/bind_helper.rb +40 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '084c1d78bfaaba922584b490202ecae778d7a43cc5258193635f2446aa5ad1b0'
|
|
4
|
+
data.tar.gz: 3986f2395f46c5e70895d38d711e04a2b314d000d5239c8417273c076fbe1632
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59e1e18beec130b63051e7f782b2f5f1e7c2a3316469b293870ffea871b61ba1ea70497fc5d4346a04355ca3ffad5b8594a6eb0de8baeca309f0dbbb29b7a234
|
|
7
|
+
data.tar.gz: a21c4d793c954ce6b017257b2fd6b946221ef2ce7d10b404d13daa7eb954bcc2bd90c869c9b703ad9ea556d5d8d0418a87fa7f5adbe3038a72a25d8f316ddfaa
|
data/src/run/core.rb
CHANGED
|
@@ -157,13 +157,7 @@ module Run
|
|
|
157
157
|
|
|
158
158
|
# @return [String]
|
|
159
159
|
def self.version
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if gemspec_files.first
|
|
163
|
-
Gem::Specification::load(gemspec_files.first).version.to_s
|
|
164
|
-
else
|
|
165
|
-
Gemspec::Metadata.new("run_tasks").read.version
|
|
166
|
-
end
|
|
160
|
+
Gemspec::Metadata.new("run_tasks").read.version
|
|
167
161
|
end
|
|
168
162
|
|
|
169
163
|
# @return [Boolean]
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'fiddle'
|
|
4
|
+
|
|
3
5
|
module Run
|
|
4
6
|
module Helper
|
|
5
7
|
class BindHelper
|
|
6
8
|
TERM_TIMEOUT = 3
|
|
7
9
|
COLORS = %i[cyan magenta yellow green blue]
|
|
8
10
|
|
|
9
|
-
def initialize(*names)
|
|
11
|
+
def initialize(*names, stdin: nil)
|
|
10
12
|
@names = names
|
|
13
|
+
@stdin_name = stdin
|
|
11
14
|
end
|
|
12
15
|
|
|
13
16
|
def run
|
|
@@ -15,10 +18,15 @@ module Run
|
|
|
15
18
|
threads = []
|
|
16
19
|
mutex = Mutex.new
|
|
17
20
|
shutting_down = false
|
|
21
|
+
use_terminal = @stdin_name && $stdin.isatty
|
|
22
|
+
|
|
23
|
+
# Prevent SIGTTOU when the parent writes to the terminal while in background.
|
|
24
|
+
Signal.trap('TTOU', 'IGNORE') if use_terminal
|
|
18
25
|
|
|
19
26
|
shutdown = lambda do
|
|
20
27
|
return if shutting_down
|
|
21
28
|
shutting_down = true
|
|
29
|
+
tcsetpgrp(Process.getpgrp) if use_terminal
|
|
22
30
|
pgids.each_value { |pgid| Process.kill('TERM', -pgid) rescue nil }
|
|
23
31
|
Thread.new do
|
|
24
32
|
sleep TERM_TIMEOUT
|
|
@@ -31,13 +39,17 @@ module Run
|
|
|
31
39
|
|
|
32
40
|
@names.each_with_index do |name, index|
|
|
33
41
|
prefix = "[#{name}]".send(COLORS[index % COLORS.size])
|
|
34
|
-
|
|
42
|
+
is_stdin_task = name == @stdin_name
|
|
43
|
+
rd, wr = IO.pipe unless is_stdin_task
|
|
35
44
|
|
|
36
45
|
pid = fork do
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
unless is_stdin_task
|
|
47
|
+
rd.close
|
|
48
|
+
$stdout.reopen(wr)
|
|
49
|
+
$stderr.reopen(wr)
|
|
50
|
+
$stdin.reopen('/dev/null')
|
|
51
|
+
wr.close
|
|
52
|
+
end
|
|
41
53
|
Process.setpgrp
|
|
42
54
|
Signal.trap('TERM') { exit 0 }
|
|
43
55
|
begin
|
|
@@ -50,12 +62,20 @@ module Run
|
|
|
50
62
|
end
|
|
51
63
|
end
|
|
52
64
|
|
|
53
|
-
|
|
65
|
+
unless is_stdin_task
|
|
66
|
+
wr.close
|
|
67
|
+
end
|
|
68
|
+
# Set pgid from the parent too to avoid a race with tcsetpgrp below.
|
|
69
|
+
Process.setpgid(pid, pid) rescue nil
|
|
54
70
|
pgids[name] = pid
|
|
55
71
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
if is_stdin_task
|
|
73
|
+
tcsetpgrp(pid) if use_terminal
|
|
74
|
+
else
|
|
75
|
+
threads << Thread.new(rd, prefix) do |pipe, pre|
|
|
76
|
+
pipe.each_line { |line| mutex.synchronize { STDOUT.write("#{pre} #{line}") } }
|
|
77
|
+
pipe.close
|
|
78
|
+
end
|
|
59
79
|
end
|
|
60
80
|
end
|
|
61
81
|
|
|
@@ -69,6 +89,16 @@ module Run
|
|
|
69
89
|
|
|
70
90
|
threads.each(&:join)
|
|
71
91
|
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
def tcsetpgrp(pgid)
|
|
96
|
+
@_tcsetpgrp ||= begin
|
|
97
|
+
libc = Fiddle.dlopen(nil)
|
|
98
|
+
Fiddle::Function.new(libc['tcsetpgrp'], [Fiddle::TYPE_INT, Fiddle::TYPE_INT], Fiddle::TYPE_INT)
|
|
99
|
+
end
|
|
100
|
+
@_tcsetpgrp.call(0, pgid)
|
|
101
|
+
end
|
|
72
102
|
end
|
|
73
103
|
end
|
|
74
104
|
end
|