vete 0.3.0 → 0.6.0
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 +31 -35
- 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: 9e19484c6c02cd403365def0a14367e2c31f302edd7b56842e863162d0178730
|
4
|
+
data.tar.gz: 303793b8c478fe08733f2da221a325d66e68b2d3ab54c89105482ef612866953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59e65ecb548ffa4ccc95f4928f83cb036cefaae98e447801c03616627557614f871f24442b331fd1f6d1211beaf8559f7b98870ea3e31a316ab22af6041d438f
|
7
|
+
data.tar.gz: 03aef3e49b3ee52dbd6867adee656d67fb6124f3eabc027732d35be04e46b0db0139a59abfc00d64079d2f4ce95b6d2cb24cb7e1f752283168196f965e028adb
|
data/lib/vete.rb
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
# Author: Steve Shreeve (steve.shreeve@gmail.com)
|
5
5
|
# Date: Mar 21, 2023
|
6
6
|
# ============================================================================
|
7
|
-
# TODO: 1) progress should update until all workers have *finished*
|
8
|
-
# ============================================================================
|
9
7
|
|
10
8
|
STDOUT.sync = true
|
11
9
|
|
@@ -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.0"
|
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,16 +116,17 @@ 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 [
|
@@ -135,25 +134,17 @@ def draw(live=0, done=0, bomb=0, jobs=0, info=nil)
|
|
135
134
|
fg("fff"),
|
136
135
|
bg("58a65c") + @char * ( gcol ) , # green (done)
|
137
136
|
bg("f1bf42") + @char * ( ycol) , # yellow (live)
|
138
|
-
bg("d85140") + " " * (@wide - gcol - ycol).ceil, # red (
|
139
|
-
go(@work + 3, @len + 5 + @wide + 3)
|
140
|
-
|
137
|
+
bg("d85140") + " " * (@wide - gcol - ycol).ceil, # red (rest)
|
138
|
+
go(@work + 3, @len + 5 + @wide + 3) , # scoot over...
|
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 1
|
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.0
|
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
|