@rip-lang/swarm 1.2.4 → 1.2.5
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.
- package/package.json +1 -1
- package/swarm.rip +35 -30
package/package.json
CHANGED
package/swarm.rip
CHANGED
|
@@ -117,7 +117,7 @@ draw = (state) ->
|
|
|
117
117
|
for slot, count of info
|
|
118
118
|
tpct = count / most
|
|
119
119
|
cols = Math.floor(ppct * tpct * wide)
|
|
120
|
-
write go(parseInt(slot) + 1, len + 5) + bg("5383ec") + char.repeat(cols) + bg()
|
|
120
|
+
write go(parseInt(slot) + 1, len + 5) + fg("fff") + bg("5383ec") + char.repeat(cols) + fg() + bg()
|
|
121
121
|
|
|
122
122
|
# summary bar
|
|
123
123
|
dpct = done / jobs
|
|
@@ -162,6 +162,7 @@ export swarm = (opts = {}) ->
|
|
|
162
162
|
char = (findArg(args, '-c', '--char') or opts.char or '•')[0]
|
|
163
163
|
doreset = args.includes('-r') or args.includes('--reset')
|
|
164
164
|
dosafe = args.includes('-s') or args.includes('--safe')
|
|
165
|
+
quiet = args.includes('-q') or args.includes('--quiet')
|
|
165
166
|
|
|
166
167
|
if workers < 1
|
|
167
168
|
console.error 'error: workers must be at least 1'
|
|
@@ -223,17 +224,19 @@ export swarm = (opts = {}) ->
|
|
|
223
224
|
|
|
224
225
|
# signal handlers
|
|
225
226
|
process.on 'SIGINT', ->
|
|
226
|
-
cursor(true)
|
|
227
|
-
write go(workers + 5, 1) + "\n"
|
|
227
|
+
cursor(true) unless quiet
|
|
228
|
+
write go(workers + 5, 1) + "\n" unless quiet
|
|
228
229
|
process.exit(1)
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
unless quiet
|
|
231
|
+
process.on 'SIGWINCH', ->
|
|
232
|
+
drawFrame(workers)
|
|
233
|
+
draw({ live, done, died, jobs, workers, info })
|
|
232
234
|
|
|
233
235
|
# draw initial frame
|
|
234
236
|
startTime = Date.now()
|
|
235
|
-
|
|
236
|
-
|
|
237
|
+
unless quiet
|
|
238
|
+
cursor(false)
|
|
239
|
+
drawFrame(workers)
|
|
237
240
|
|
|
238
241
|
# create workers and dispatch tasks
|
|
239
242
|
allWorkers = []
|
|
@@ -254,8 +257,9 @@ export swarm = (opts = {}) ->
|
|
|
254
257
|
taskPath = tasks[taskIdx++]
|
|
255
258
|
inflight[slot] = taskPath
|
|
256
259
|
live++
|
|
257
|
-
|
|
258
|
-
|
|
260
|
+
unless quiet
|
|
261
|
+
write go(slot + 1, len + 5 + wide + 3) + " " + taskPath.split('/').pop() + clear(true)
|
|
262
|
+
draw({ live, done, died, jobs, workers, info })
|
|
259
263
|
worker.postMessage { type: 'task', taskPath }
|
|
260
264
|
else
|
|
261
265
|
inflight[slot] = null
|
|
@@ -282,7 +286,7 @@ export swarm = (opts = {}) ->
|
|
|
282
286
|
live--
|
|
283
287
|
done++
|
|
284
288
|
info[slot]++
|
|
285
|
-
draw({ live, done, died, jobs, workers, info })
|
|
289
|
+
draw({ live, done, died, jobs, workers, info }) unless quiet
|
|
286
290
|
dispatchNext(w, slot)
|
|
287
291
|
when 'failed'
|
|
288
292
|
move(msg.taskPath, _died)
|
|
@@ -292,7 +296,7 @@ export swarm = (opts = {}) ->
|
|
|
292
296
|
live--
|
|
293
297
|
died++
|
|
294
298
|
info[slot]++
|
|
295
|
-
draw({ live, done, died, jobs, workers, info })
|
|
299
|
+
draw({ live, done, died, jobs, workers, info }) unless quiet
|
|
296
300
|
dispatchNext(w, slot)
|
|
297
301
|
|
|
298
302
|
w.on 'error', (err) ->
|
|
@@ -307,7 +311,7 @@ export swarm = (opts = {}) ->
|
|
|
307
311
|
live--
|
|
308
312
|
died++
|
|
309
313
|
info[slot]++
|
|
310
|
-
draw({ live, done, died, jobs, workers, info })
|
|
314
|
+
draw({ live, done, died, jobs, workers, info }) unless quiet
|
|
311
315
|
# respawn if there's still work to do
|
|
312
316
|
if done + died < jobs
|
|
313
317
|
spawnWorker(slot)
|
|
@@ -319,23 +323,24 @@ export swarm = (opts = {}) ->
|
|
|
319
323
|
for slot in [1..count]
|
|
320
324
|
spawnWorker(slot)
|
|
321
325
|
|
|
322
|
-
# final redraw — fill all worker bars and show per-worker stats
|
|
323
|
-
secs = (Date.now() - startTime) / 1000
|
|
324
|
-
for slot of info
|
|
325
|
-
s = parseInt(slot)
|
|
326
|
-
n = info[slot]
|
|
327
|
-
rate = if secs > 0 then (n / secs).toFixed(1) else '—'
|
|
328
|
-
write go(s + 1, len + 5) + bg("5383ec") + char.repeat(wide) + bg() + " │ #{n} jobs @ #{rate}/sec" + clear(true)
|
|
329
|
-
draw({ live: 0, done, died, jobs, workers, info })
|
|
330
|
-
|
|
331
326
|
# summary
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
327
|
+
secs = (Date.now() - startTime) / 1000
|
|
328
|
+
if quiet
|
|
329
|
+
p "#{secs.toFixed(2)} secs for #{jobs} jobs by #{workers} workers" + (if secs > 0 then " @ #{(jobs / secs).toFixed(2)} jobs/sec" else "")
|
|
330
|
+
else
|
|
331
|
+
for slot of info
|
|
332
|
+
s = parseInt(slot)
|
|
333
|
+
n = info[slot]
|
|
334
|
+
rate = if secs > 0 then (n / secs).toFixed(1) else '—'
|
|
335
|
+
write go(s + 1, len + 5) + fg("fff") + bg("5383ec") + char.repeat(wide) + fg() + bg() + " │ #{n} jobs @ #{rate}/sec" + clear(true)
|
|
336
|
+
draw({ live: 0, done, died, jobs, workers, info })
|
|
337
|
+
cursor(true)
|
|
338
|
+
write go(workers + 5, 1)
|
|
339
|
+
write "#{secs.toFixed(2)} secs"
|
|
340
|
+
write " for #{jobs} jobs"
|
|
341
|
+
write " by #{workers} workers"
|
|
342
|
+
write " @ #{(jobs / secs).toFixed(2)} jobs/sec" if secs > 0
|
|
343
|
+
write "\n\n"
|
|
339
344
|
|
|
340
345
|
# ==============================================================================
|
|
341
346
|
# CLI helpers
|
|
@@ -344,7 +349,7 @@ export swarm = (opts = {}) ->
|
|
|
344
349
|
# flags that swarm consumes (with value)
|
|
345
350
|
_flagsWithValue = ['-w', '--workers', '-b', '--bar', '-c', '--char']
|
|
346
351
|
# flags that swarm consumes (standalone)
|
|
347
|
-
_flagsAlone = ['-r', '--reset', '-s', '--safe', '-h', '--help', '-v', '--version']
|
|
352
|
+
_flagsAlone = ['-r', '--reset', '-s', '--safe', '-q', '--quiet', '-h', '--help', '-v', '--version']
|
|
348
353
|
|
|
349
354
|
findArg = (args, short, long) ->
|
|
350
355
|
for arg, i in args
|