Class: PPool::TerminalProcessController

Inherits:
TimedProcessController show all
Defined in:
lib/terminal_process_controller.rb

Instance Method Summary collapse

Methods inherited from TimedProcessController

#dec_size, #delay, #finished, #finishing, #finishing?, #inc_size, #num_processes, #process_started, #running?, #set_size

Methods inherited from ShellProcessController

#delete_log_file, #info, #process_ended, #run_process

Methods inherited from BasicProcessController

#delay, #info, #num_processes, #process_ended, #process_started, #run_process, #running?, #time_running, #time_running_secs

Constructor Details

#initialize(size, delay, script, time, logdir, rmlogs) ⇒ TerminalProcessController

Returns a new instance of TerminalProcessController.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/terminal_process_controller.rb', line 32

def initialize(size, delay, script, time, logdir, rmlogs)
  super(size, delay, script, time, logdir, rmlogs)
  @msg = ""
  @last_stats = {}
  @count = 0

  Signal.trap('INT') do 
	terminate
  end

end

Instance Method Details

#process_keysObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/terminal_process_controller.rb', line 69

def process_keys

  case read_ch
  when '+'
    inc_size
	@last_stats = {}
	puts ""
  when '-'
    dec_size
	@last_stats = {}
	puts ""
  when 'q', 'Q'
    finishing
	@last_stats = {}
	puts ""
  when 'x', 'X'
	terminate
  end

end

#progress(stats) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/terminal_process_controller.rb', line 45

def progress(stats)

   if stats != @last_stats
	 if @count % 20 == 0

 puts "----------------------------------------------"
 puts " Time     | Size  Active  Started Ended Errors"
 puts "=============================================="

	 end
	 puts(" %s | %4d   %4d   %4d   %4d   %4d\n" % [time_running, @size, stats[:active_processes], stats[:processes_started], stats[:processes_ended], stats[:errors]])
	 @last_stats = stats
	 @count = @count + 1
   end

   process_keys

  if finishing?
	if stats[:active_processes] == 0
	  finished
	end
  end
end

#read_chObject



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/terminal_process_controller.rb', line 90

def read_ch
  begin
	system("stty raw") 
	if $stdin.ready?
	  c = $stdin.getc
	  return c.chr
	end
  ensure
	system("stty -raw")
  end
  return nil
end

#terminateObject



104
105
106
107
108
# File 'lib/terminal_process_controller.rb', line 104

def terminate
  system("stty -raw")
  puts ""
  exit(0)
end