vete 0.3.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vete.rb +34 -38
  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: ebef08e0bd4e613f05c177ca2ed9aebff1c9374f6cc89bd09424592bc82d1df4
4
+ data.tar.gz: fa9226523af0c7ee7e2f2c64a3a0e618ccfcb1b1fd6bf82b4af0406c5b3d115a
5
5
  SHA512:
6
- metadata.gz: 0df917b8b8bb7cc72e0903130543e4e700b4264e8119b9f65d5c038cfa2dfb3538804945df489fcc27fa781deb18c923a2c540087dbf95b60c50f8a1eca48890
7
- data.tar.gz: d05bac44008d71d71738b234d0d2f750fdfdaa4c5d3de24263dd72e1888039165c5d902bdb01510712e0741750ae57dca16a679728c9cf5e97384227d1af80b2
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 21, 2023
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.3.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
- @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,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
- 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 [
134
133
  go(@work + 3, @len + 5),
135
134
  fg("fff"),
136
- bg("58a65c") + @char * ( gcol ) , # green (done)
137
- 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 "),
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
- 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 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(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.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.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