Class: TerminalProcessController

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

Instance Method Summary collapse

Methods inherited from ShellProcessController

#info, #run_process

Methods inherited from BasicProcessController

#info, #run_process, #time_running

Constructor Details

#initialize(size, script, logdir) ⇒ TerminalProcessController

Returns a new instance of TerminalProcessController.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/terminal_process_controller.rb', line 7

def initialize(size, script, logdir)
  super(script, logdir)
  @finishing = false
  @finished = false
  @size = size
  @msg = ""
  @last_stats = {}
  @count = 0

  Signal.trap('INT') do 
    finished
  end

end

Instance Method Details

#delayObject



63
64
65
# File 'lib/terminal_process_controller.rb', line 63

def delay
  return 0.1
end

#finishedObject



107
108
109
110
111
# File 'lib/terminal_process_controller.rb', line 107

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

#num_processesObject



26
27
28
# File 'lib/terminal_process_controller.rb', line 26

def num_processes
  return @size
end

#process_ended(pid, status) ⇒ Object



33
34
# File 'lib/terminal_process_controller.rb', line 33

def process_ended(pid, status)
end

#process_keysObject



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

def process_keys
 
  case read_ch
  when '+'
    @size = @size + 1
    @last_stats = {}
    puts ""
  when '-'
    @size = @size - 1
    if @size < 0
      @size = 0
    end
    @last_stats = {}
    puts ""
  when 'q', 'Q'
    @size = 0
    @finishing = true
    @last_stats = {}
    puts ""
  when 'x', 'X'
    finished
  end

end

#process_started(pid, num_processes) ⇒ Object



30
31
# File 'lib/terminal_process_controller.rb', line 30

def process_started(pid, num_processes) 
end

#progress(stats) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/terminal_process_controller.rb', line 36

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
    info "finishing #{stats[:active_processes]}"
    if stats[:active_processes] == 0
      @finished = true
    end
  end


end

#read_chObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/terminal_process_controller.rb', line 93

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

#running?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/terminal_process_controller.rb', line 22

def running?
  return !@finished
end