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.



24
25
26
27
28
29
30
31
32
33
# File 'lib/opsicle/monitor/app.rb', line 24

def initialize(environment, options)
  @running       = false
  @restarting    = false
  @threads       = {}
  @deployment_id = options[:deployment_id]

  # Make client with correct configuration available to monitor spies
  App.client = Client.new(environment)
  @deploy = Opsicle::Deployment.new(@deployment_id, App.client) if @deployment_id
end

Class Attribute Details

.clientObject

Returns the value of attribute client.



21
22
23
# File 'lib/opsicle/monitor/app.rb', line 21

def client
  @client
end

Instance Attribute Details

#deployObject (readonly)

Returns the value of attribute deploy.



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

def deploy
  @deploy
end

#deployment_idObject (readonly)

Returns the value of attribute deployment_id.



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

def deployment_id
  @deployment_id
end

#restartingObject (readonly)

Returns the value of attribute restarting.



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

def restarting
  @restarting
end

#runningObject (readonly)

Returns the value of attribute running.



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

def running
  @running
end

Instance Method Details

#do_command(key) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/opsicle/monitor/app.rb', line 80

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



76
77
78
# File 'lib/opsicle/monitor/app.rb', line 76

def restart
  @restarting = true
end

#startObject



35
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
62
63
# File 'lib/opsicle/monitor/app.rb', line 35

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

    if @deploy
      @threads[:check_status] ||= Thread.new do
        refresh_deploy_status_loop # refresh not so frequently
      end
    end

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

#stop(options = {}) ⇒ Object



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

def stop(options={})
  options = { error: nil, message: "" }.merge(options)

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

  options[:error] ? raise(options[:error]) : raise(QuitMonitor, options[:message])
end