Class: Opsicle::Monitor::App

Inherits:
Object
  • Object
show all
Defined in:
lib/opsicle/monitor/app.rb

Constant Summary collapse

API_POLLING_INTERVAL =
10
SCREEN_REFRESH_INTERVAL =
5

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment, options) ⇒ App

Returns a new instance of App.



21
22
23
24
25
26
27
28
# File 'lib/opsicle/monitor/app.rb', line 21

def initialize(environment, options)
  @running    = false
  @restarting = false
  @threads    = {}

  # Make client with correct configuration available to monitor spies
  App.client = Client.new(environment)
end

Class Attribute Details

.clientObject

Returns the value of attribute client.



18
19
20
# File 'lib/opsicle/monitor/app.rb', line 18

def client
  @client
end

Instance Attribute Details

#restartingObject (readonly)

Returns the value of attribute restarting.



15
16
17
# File 'lib/opsicle/monitor/app.rb', line 15

def restarting
  @restarting
end

#runningObject (readonly)

Returns the value of attribute running.



14
15
16
# File 'lib/opsicle/monitor/app.rb', line 14

def running
  @running
end

Instance Method Details

#do_command(key) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/opsicle/monitor/app.rb', line 66

def do_command(key)
  command = { 'q' => :stop,
              'h' => [:set_screen, :help],
              'b' => :open_opsworks_browser,
              'd' => [:set_screen, :deployments],
              'i' => [:set_screen, :instances], }[key]
  command ||= :invalid_input

  send *command unless command == :invalid_input

  wakey_wakey # wake threads for immediate response
end

#restartObject



62
63
64
# File 'lib/opsicle/monitor/app.rb', line 62

def restart
  @restarting = true
end

#startObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/opsicle/monitor/app.rb', line 30

def start
  begin
    @running = true

    setup

    @threads[:command] ||= Thread.new do
      command_loop # listen for commands
    end

    @threads[:refresh_screen] ||= Thread.new do
      refresh_screen_loop # refresh frequently
    end

    @threads[:refresh_data] ||= Thread.new do
      refresh_data_loop # refresh not so frequently
    end

    @threads.each { |tname, t| t.join }
  ensure
    cleanup
  end
end

#stopObject

Raises:



54
55
56
57
58
59
60
# File 'lib/opsicle/monitor/app.rb', line 54

def stop
  @running = false
  @screen.close
  @screen = nil # Ruby curses lib doesn't have closed?(), so we set to nil, just in case

  raise QuitMonitor
end