vete 0.3.0 → 0.6.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vete.rb +31 -35
  3. data/test/example.rb +4 -2
  4. data/test/vete.gif +0 -0
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31328c3602f1174d697b56c9d0b8049986b68151975ed05c2febe3bab04d0c00
4
- data.tar.gz: e4d99dd8303a7bcc8d589f66bb6ad0a0e2b79bfb718c7f2856f2e3a7aa558e63
3
+ metadata.gz: 9e19484c6c02cd403365def0a14367e2c31f302edd7b56842e863162d0178730
4
+ data.tar.gz: 303793b8c478fe08733f2da221a325d66e68b2d3ab54c89105482ef612866953
5
5
  SHA512:
6
- metadata.gz: 0df917b8b8bb7cc72e0903130543e4e700b4264e8119b9f65d5c038cfa2dfb3538804945df489fcc27fa781deb18c923a2c540087dbf95b60c50f8a1eca48890
7
- data.tar.gz: d05bac44008d71d71738b234d0d2f750fdfdaa4c5d3de24263dd72e1888039165c5d902bdb01510712e0741750ae57dca16a679728c9cf5e97384227d1af80b2
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.3.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
- @bomb = File.join(@vete, "bomb")
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, @bomb]
79
- list.each {|path| File.mkdir_p(path, force: true, secure: true) }
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(@bomb, "*")).sort.each {|path| FileUtils.touch(path) }
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(path, force: true, secure: true)
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, bomb=0, jobs=0, info=nil)
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
- lpct = live.to_f / jobs
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 = dpct * tpct * @wide
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 (left)
139
- go(@work + 3, @len + 5 + @wide + 3) + " %.1f%% done " % [dpct * 100],
140
- bomb == 0 ? nil : (bg + " " + bg("f1bf42") + " #{bomb} bombed "),
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
- live = 0
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 : @bomb)
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, bomb, jobs, info.dup)
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(slot, path)
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(slot, task)
9
+ def perform(task)
8
10
  sleep rand
9
11
  secs = Time.now - @time
10
- exit 4 if rand < 0.02
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.3.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.8
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