dry-stack 0.1.55 → 0.1.57
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/bin/rparallel +60 -13
- data/lib/dry-stack/stack.rb +17 -4
- data/lib/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: 31df24a38beb3fafd6a02537928ab12544183eeb4edeffb8fcdac2033010af3d
|
|
4
|
+
data.tar.gz: 0b3137a155bca51c5464a442f76600517c87e47dcb4234dd7495eac16a2d2cfd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c27e4576b6f0a01d9fa79124e80447f9b908bef0eca50c595cd466fd2311b52c438b6efe5ab0e82f2f14e153a256cafa08a7178490368bb78970254e989a7a5e
|
|
7
|
+
data.tar.gz: 12aff94e708e1364c0b758c240fbeed909c6582565f9a3939bfcd1c871ab892d03bd253307432eb681a0abad2e79cfd33d58fb77f25ee0995843585b470a8c85
|
data/bin/rparallel
CHANGED
|
@@ -10,6 +10,15 @@ Task = Struct.new(:number, :command, :started_at, :ended_at, :exit_code, keyword
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
class RParallel
|
|
13
|
+
COLORS = {
|
|
14
|
+
bold: "\e[1m",
|
|
15
|
+
dim: "\e[2m",
|
|
16
|
+
green: "\e[32m",
|
|
17
|
+
red: "\e[31m",
|
|
18
|
+
cyan: "\e[36m",
|
|
19
|
+
reset: "\e[0m"
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
13
22
|
def self.run(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr)
|
|
14
23
|
return usage(stdout) if argv == ["--help"] || argv == ["-h"]
|
|
15
24
|
|
|
@@ -21,20 +30,22 @@ class RParallel
|
|
|
21
30
|
commands = stdin.each_line.map(&:strip).reject(&:empty?)
|
|
22
31
|
tasks = commands.each_with_index.map { |command, index| Task.new(number: index + 1, command:) }
|
|
23
32
|
|
|
24
|
-
|
|
33
|
+
color = color_enabled?
|
|
34
|
+
output_mutex = Mutex.new
|
|
35
|
+
tasks.map { |task| Thread.new { run_task(task, stdout, stderr, output_mutex, color) } }.each(&:join)
|
|
25
36
|
print_report(tasks, stdout)
|
|
26
37
|
|
|
27
38
|
tasks.all? { _1.exit_code.zero? } ? 0 : 1
|
|
28
39
|
end
|
|
29
40
|
|
|
30
|
-
def self.run_task(task, stdout, stderr)
|
|
41
|
+
def self.run_task(task, stdout, stderr, output_mutex, color)
|
|
31
42
|
task.started_at = monotonic_time
|
|
32
43
|
|
|
33
44
|
Open3.popen3("sh", "-c", task.command) do |child_stdin, child_stdout, child_stderr, wait_thread|
|
|
34
45
|
child_stdin.close
|
|
35
46
|
readers = [
|
|
36
|
-
Thread.new {
|
|
37
|
-
Thread.new {
|
|
47
|
+
Thread.new { stream_output(child_stdout, stdout, task.number, output_mutex) },
|
|
48
|
+
Thread.new { stream_output(child_stderr, stderr, task.number, output_mutex, color: :red, enabled: color) }
|
|
38
49
|
]
|
|
39
50
|
readers.each(&:join)
|
|
40
51
|
task.exit_code = wait_thread.value.exitstatus || 1
|
|
@@ -46,26 +57,61 @@ class RParallel
|
|
|
46
57
|
task.ended_at = monotonic_time
|
|
47
58
|
end
|
|
48
59
|
|
|
60
|
+
def self.stream_output(source, target, job_number, output_mutex, color: nil, enabled: false)
|
|
61
|
+
source.each_line do |line|
|
|
62
|
+
output = "[Job #{job_number}] #{line.chomp}"
|
|
63
|
+
output_mutex.synchronize { target.puts color ? colorize(output, color, enabled) : output }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
49
67
|
def self.print_report(tasks, stdout)
|
|
50
68
|
rows = tasks.map do |task|
|
|
51
69
|
[task.number.to_s, task.status, task.exit_code.to_s, format("%.3fs", task.duration), task.command]
|
|
52
70
|
end
|
|
53
|
-
|
|
71
|
+
header = ["#", "status", "exit", "duration", "command"]
|
|
72
|
+
widths = column_widths([header, *rows])
|
|
73
|
+
color = color_enabled?
|
|
54
74
|
|
|
55
75
|
stdout.puts
|
|
56
|
-
stdout.puts "rparallel report"
|
|
57
|
-
stdout.puts
|
|
58
|
-
|
|
76
|
+
stdout.puts colorize("rparallel report", :bold, color)
|
|
77
|
+
stdout.puts colorize(border(widths), :dim, color)
|
|
78
|
+
stdout.puts format_row(header, widths, color:, header: true)
|
|
79
|
+
stdout.puts colorize(border(widths), :dim, color)
|
|
80
|
+
rows.each { stdout.puts format_row(_1, widths, color:) }
|
|
81
|
+
stdout.puts colorize(border(widths), :dim, color)
|
|
59
82
|
end
|
|
60
83
|
|
|
61
84
|
def self.column_widths(rows)
|
|
62
85
|
rows.transpose.map { _1.map(&:length).max }
|
|
63
86
|
end
|
|
64
87
|
|
|
65
|
-
def self.format_row(row, widths)
|
|
66
|
-
row.each_with_index.map do |value, index|
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
def self.format_row(row, widths, color:, header: false)
|
|
89
|
+
cells = row.each_with_index.map do |value, index|
|
|
90
|
+
padded = value.ljust(widths[index])
|
|
91
|
+
header ? colorize(padded, :cyan, color) : colorize_report_cell(padded, row, index, color)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
"| #{cells.join(' | ')} |"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def self.border(widths)
|
|
98
|
+
"+-#{widths.map { '-' * _1 }.join('-+-')}-+"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def self.colorize_report_cell(value, row, index, color)
|
|
102
|
+
return colorize(value, row[1] == "ok" ? :green : :red, color) if [1, 2].include?(index)
|
|
103
|
+
|
|
104
|
+
value
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def self.colorize(value, color_name, enabled)
|
|
108
|
+
return value unless enabled
|
|
109
|
+
|
|
110
|
+
"#{COLORS.fetch(color_name)}#{value}#{COLORS.fetch(:reset)}"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.color_enabled?
|
|
114
|
+
ENV["NO_COLOR"].nil? && ENV["RPARALLEL_NO_COLOR"].nil?
|
|
69
115
|
end
|
|
70
116
|
|
|
71
117
|
def self.usage(stdout)
|
|
@@ -77,7 +123,8 @@ class RParallel
|
|
|
77
123
|
|
|
78
124
|
def self.monotonic_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
79
125
|
|
|
80
|
-
private_class_method :run_task, :print_report, :column_widths, :format_row, :
|
|
126
|
+
private_class_method :run_task, :stream_output, :print_report, :column_widths, :format_row, :border,
|
|
127
|
+
:colorize_report_cell, :colorize, :color_enabled?, :usage, :monotonic_time
|
|
81
128
|
end
|
|
82
129
|
|
|
83
130
|
exit RParallel.run(ARGV)
|
data/lib/dry-stack/stack.rb
CHANGED
|
@@ -415,18 +415,31 @@ module Dry
|
|
|
415
415
|
(@after_blocks ||=[]) << block
|
|
416
416
|
end
|
|
417
417
|
|
|
418
|
+
def normalize_service_hook_args(name, opts)
|
|
419
|
+
if name.is_a?(Hash) && opts.empty?
|
|
420
|
+
opts = name
|
|
421
|
+
name = nil
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
opts = opts.dup
|
|
425
|
+
except = [opts.delete(:except)].flatten.compact
|
|
426
|
+
[[name].flatten.compact, opts, except]
|
|
427
|
+
end
|
|
428
|
+
|
|
418
429
|
def BeforeService(name = nil, opts = {}, &block)
|
|
419
|
-
|
|
430
|
+
names, opts, except = normalize_service_hook_args(name, opts)
|
|
431
|
+
(@before_blocks ||=[]).push names:, except:,
|
|
420
432
|
block: ->(s_name) {
|
|
421
433
|
_ServiceImplementation s_name, opts, &block
|
|
422
434
|
}
|
|
423
435
|
end
|
|
424
436
|
|
|
425
437
|
def AfterService(name = nil, opts = {}, &block)
|
|
438
|
+
names, opts, except = normalize_service_hook_args(name, opts)
|
|
426
439
|
After do
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
440
|
+
hook_names = names.empty? ? @services.keys : names
|
|
441
|
+
hook_names -= except
|
|
442
|
+
hook_names.each do |s_name|
|
|
430
443
|
_ServiceImplementation s_name, opts, &block
|
|
431
444
|
end
|
|
432
445
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dry-stack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.57
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Artyom B
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|