vete 0.3.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vete.rb +34 -38
- data/test/example.rb +4 -2
- data/test/vete.gif +0 -0
- 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: ebef08e0bd4e613f05c177ca2ed9aebff1c9374f6cc89bd09424592bc82d1df4
|
4
|
+
data.tar.gz: fa9226523af0c7ee7e2f2c64a3a0e618ccfcb1b1fd6bf82b4af0406c5b3d115a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 387161f8cff69edcaec6a35a7e08dfa9fc9266f411e69bd48d764db10f3a37d2690f0b3a5c1018b48b4edb6adc83daa25cd96326d9565a981a5a411ea62aff92
|
7
|
+
data.tar.gz: b192c68b8dfa2d3c53607a2ecfb50308c1ef86a623322b2c5285ed34b848a8fae409ddb90c6a7d618e59bb1b61cbafd19fa72328e17aa8810a4084d63e6d4a20
|
data/lib/vete.rb
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
# vete - Ruby CLI to spawn processes to get work done
|
3
3
|
#
|
4
4
|
# Author: Steve Shreeve (steve.shreeve@gmail.com)
|
5
|
-
# Date: Mar
|
6
|
-
# ============================================================================
|
7
|
-
# TODO: 1) progress should update until all workers have *finished*
|
5
|
+
# Date: Mar 22, 2023
|
8
6
|
# ============================================================================
|
9
7
|
|
10
8
|
STDOUT.sync = true
|
@@ -21,7 +19,7 @@ trap("INT" ) { print clear + go; abort "\n" }
|
|
21
19
|
trap("WINCH") { print clear or draw if @pid == Process.pid }
|
22
20
|
|
23
21
|
OptionParser.new.instance_eval do
|
24
|
-
@version = "0.
|
22
|
+
@version = "0.6.1"
|
25
23
|
@banner = "usage: #{program_name} [options]"
|
26
24
|
|
27
25
|
on "-b", "--bar <width>" , "Progress bar width, in characters", Integer
|
@@ -57,7 +55,7 @@ end
|
|
57
55
|
@todo = File.join(@vete, "todo")
|
58
56
|
@live = File.join(@vete, "live")
|
59
57
|
@done = File.join(@vete, "done")
|
60
|
-
@
|
58
|
+
@died = File.join(@vete, "died")
|
61
59
|
|
62
60
|
def move(path, dest)
|
63
61
|
dest = File.join(dest, File.basename(path))
|
@@ -75,17 +73,17 @@ end
|
|
75
73
|
|
76
74
|
def vete_init
|
77
75
|
nuke
|
78
|
-
list = [@todo, @live, @done, @
|
79
|
-
list.each {|path|
|
76
|
+
list = [@todo, @live, @done, @died]
|
77
|
+
list.each {|path| FileUtils.mkdir_p(path) }
|
80
78
|
end
|
81
79
|
|
82
80
|
def vete_retry
|
83
|
-
list = Dir.glob(File.join(@
|
81
|
+
list = Dir.glob(File.join(@died, "*")).sort.each {|path| FileUtils.touch(path) }
|
84
82
|
move(list, @todo)
|
85
83
|
end
|
86
84
|
|
87
85
|
def vete_todo(path)
|
88
|
-
FileUtils.touch(
|
86
|
+
FileUtils.touch(File.join(@todo, path.to_s))
|
89
87
|
end
|
90
88
|
|
91
89
|
# ==[ Drawing ]===============================================================
|
@@ -104,7 +102,7 @@ def hx(str=nil); str =~ /\A#?(?:(\h\h)(\h\h)(\h\h)|(\h)(\h)(\h))\z/ or return
|
|
104
102
|
[r.hex, g.hex, b.hex] * ";"
|
105
103
|
end
|
106
104
|
|
107
|
-
def draw(live=0, done=0,
|
105
|
+
def draw(live=0, done=0, died=0, jobs=0, info=nil)
|
108
106
|
|
109
107
|
# outer box
|
110
108
|
unless info
|
@@ -118,42 +116,35 @@ def draw(live=0, done=0, bomb=0, jobs=0, info=nil)
|
|
118
116
|
end
|
119
117
|
|
120
118
|
# worker bars
|
121
|
-
|
122
|
-
dpct = done.to_f / jobs
|
119
|
+
ppct = (done + died).to_f / jobs
|
123
120
|
most = info.values.max
|
124
121
|
info.each do |slot, this|
|
125
122
|
tpct = this.to_f / most
|
126
|
-
cols =
|
123
|
+
cols = ppct * tpct * @wide
|
127
124
|
print go(slot + 1, @len + 5) + bg("5383ec") + @char * cols
|
128
125
|
end
|
129
126
|
|
130
127
|
# summary bar
|
128
|
+
dpct = done.to_f / jobs
|
129
|
+
lpct = live.to_f / jobs
|
131
130
|
gcol = dpct * @wide
|
132
131
|
ycol = lpct * @wide
|
133
132
|
print [
|
134
133
|
go(@work + 3, @len + 5),
|
135
134
|
fg("fff"),
|
136
|
-
bg("58a65c") + @char * ( gcol )
|
137
|
-
bg("f1bf42") + @char * ( ycol)
|
138
|
-
bg("d85140") + " " * (@wide - gcol - ycol).ceil, # red (
|
139
|
-
go(@work + 3, @len + 5 + @wide + 3)
|
140
|
-
|
135
|
+
bg("58a65c") + @char * ( gcol ), # green (done)
|
136
|
+
bg("f1bf42") + @char * ( ycol), # yellow (live)
|
137
|
+
bg("d85140") + " " * (@wide - gcol - ycol).ceil, # red (rest)
|
138
|
+
go(@work + 3, @len + 5 + @wide + 3),
|
139
|
+
bg("5383ec") + " %.1f%% " % [ppct * 100], # blue (done + died)
|
140
|
+
done > 0 ? (bg + " " + bg("58a65c") + " #{done} done ") : nil,
|
141
|
+
died > 0 ? (bg + " " + bg("d85140") + " #{died} died ") : nil,
|
141
142
|
].join
|
142
143
|
|
143
144
|
# clear colors
|
144
145
|
print fg + bg
|
145
146
|
end
|
146
147
|
|
147
|
-
# ==[ Simulate job creation, add helpers so vete makes this easy ]============
|
148
|
-
|
149
|
-
FileUtils.rm_rf @vete
|
150
|
-
FileUtils.mkdir_p @todo
|
151
|
-
FileUtils.mkdir_p @live
|
152
|
-
FileUtils.mkdir_p @done
|
153
|
-
FileUtils.mkdir_p @bomb
|
154
|
-
|
155
|
-
100.times {|i| FileUtils.touch(File.join(@todo, (i + 1).to_s)) }
|
156
|
-
|
157
148
|
# ==[ Configure workers ]=====================================================
|
158
149
|
|
159
150
|
@len = @work.to_s.size
|
@@ -161,17 +152,19 @@ FileUtils.mkdir_p @bomb
|
|
161
152
|
@que = Thread::Queue.new; @work.times {|slot| @que << (slot + 1) }
|
162
153
|
|
163
154
|
begin
|
155
|
+
setup if defined?(setup)
|
156
|
+
|
164
157
|
list = Dir[File.join(@todo, "*")]
|
158
|
+
|
159
|
+
live = 0
|
160
|
+
done = 0
|
161
|
+
died = 0
|
165
162
|
jobs = list.size
|
166
163
|
info = Hash.new(0)
|
167
164
|
|
168
|
-
setup if defined?(setup)
|
169
|
-
|
170
165
|
cursor(false)
|
171
166
|
draw
|
172
|
-
|
173
|
-
done = 0
|
174
|
-
bomb = 0
|
167
|
+
|
175
168
|
time = Time.now
|
176
169
|
Thread.new do
|
177
170
|
list.each_with_index do |path, task|
|
@@ -184,26 +177,29 @@ begin
|
|
184
177
|
if chld = fork # parent
|
185
178
|
Thread.new do
|
186
179
|
okay = Process.waitpid2(chld)[1] == 0
|
187
|
-
move(path, okay ? @done : @
|
180
|
+
move(path, okay ? @done : @died)
|
188
181
|
@que.push(slot)
|
189
182
|
@mtx.synchronize {
|
190
183
|
live -= 1
|
191
|
-
done += 1
|
192
|
-
bomb += 1 unless okay
|
184
|
+
okay ? (done += 1) : (died += 1)
|
193
185
|
info[slot] += 1
|
194
186
|
}
|
195
187
|
end
|
196
|
-
draw(live, done,
|
188
|
+
draw(live, done, died, jobs, info.dup)
|
197
189
|
else
|
198
190
|
case @wait
|
199
191
|
when "rand" then sleep rand(@work)
|
200
192
|
when "task" then sleep task
|
201
193
|
when Numeric then sleep task * @wait
|
202
194
|
end if task < @work
|
203
|
-
perform(
|
195
|
+
perform(path)
|
204
196
|
exit
|
205
197
|
end
|
206
198
|
end
|
199
|
+
while @que.size != @work
|
200
|
+
sleep 0.3
|
201
|
+
draw(live, done, died, jobs, info.dup)
|
202
|
+
end
|
207
203
|
end.join
|
208
204
|
secs = Time.now.to_f - time.to_f
|
209
205
|
|
data/test/example.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
def setup
|
4
|
+
vete_init
|
5
|
+
100.times {|i| vete_todo(i + 1) }
|
4
6
|
@time = Time.now
|
5
7
|
end
|
6
8
|
|
7
|
-
def perform(
|
9
|
+
def perform(task)
|
8
10
|
sleep rand
|
9
11
|
secs = Time.now - @time
|
10
|
-
exit
|
12
|
+
exit 1 if rand < 0.03
|
11
13
|
end
|
12
14
|
|
13
15
|
require_relative "../lib/vete"
|
data/test/vete.gif
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
|
-
rubygems_version: 3.4.
|
45
|
+
rubygems_version: 3.4.9
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
48
|
summary: Ruby CLI to spawn processes to get work done
|