Class: WatchedProcessGroup

Inherits:
Array
  • Object
show all
Defined in:
lib/stream2tracks/process.rb

Overview

A WatchedProcessGroup is a group of processes running in parallel, all of which can collectively be watched to indicate progress so far. It also supports visually representing progress of all processes in the group as a progress bar.

Instance Method Summary collapse

Instance Method Details

#watch(options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stream2tracks/process.rb', line 8

def watch options
	@bar=nil
	update_bar=proc do |current,total|
 # FIXME: remove hardwired 'Downloading' label
 @bar=ProgressBar.new('Downloading',total,$stderr) if total!=@old_total or @bar.nil?
 @old_total=total
 @bar.set current
	end

	all_done=false

	until all_done do
 all_done=true
 current,@old_total,total=0,0,0
 each do |_|
		begin
  status=_.watch options
		rescue RuntimeError => e
  # FIXME: @log belongs to StreamTrackRipper instance, not WatchedProcessGroup!
  # TODO: wrap in an error handler to both log and print to stderr
  @log.error e.message
  $stderr.puts "\nE: %s: %s" % [@cmd,e.message]
  delete _
		end
		if status.current
  # The reported totals may not be accurate. Rather
  # than recompute the actual total when the track
  # finishes, just accumulate the reported total
  # to improve accuracy of the progress bar.
  current+=status.eof ? status.total : status.current
  total+=status.total
		end
		all_done=false unless status.eof
 end
 update_bar[current,total] if total>0
	end

	@bar.finish if @bar
end