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

#erase_inputObject



94
95
96
# File 'lib/terminal_process_controller.rb', line 94

def erase_input 
    puts "\r "
end

#process_keysObject



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

def process_keys

  c = read_ch
  case c
  when '+'
    inc_size
	@last_stats = {}
	erase_input
  when '-'
    dec_size
	@last_stats = {}
	erase_input
  when '0'..'9'
    set_size(c.to_i)
	erase_input
  when 'q', 'Q'
    finishing
	@last_stats = {}
	erase_input
  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 Avg Elapsed"
 puts "=========================================================="

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

   process_keys

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

#read_chObject



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/terminal_process_controller.rb', line 98

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



112
113
114
115
116
# File 'lib/terminal_process_controller.rb', line 112

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