Class: Opsicle::Monitor::App
- Inherits:
-
Object
- Object
- Opsicle::Monitor::App
- Defined in:
- lib/opsicle/monitor/app.rb
Constant Summary collapse
- API_POLLING_INTERVAL =
10
- SCREEN_REFRESH_INTERVAL =
5
Class Attribute Summary collapse
-
.client ⇒ Object
Returns the value of attribute client.
Instance Attribute Summary collapse
-
#deploy ⇒ Object
readonly
Returns the value of attribute deploy.
-
#deployment_id ⇒ Object
readonly
Returns the value of attribute deployment_id.
-
#restarting ⇒ Object
readonly
Returns the value of attribute restarting.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
Instance Method Summary collapse
- #do_command(key) ⇒ Object
-
#initialize(environment, options) ⇒ App
constructor
A new instance of App.
- #restart ⇒ Object
- #start ⇒ Object
- #stop(options = {}) ⇒ Object
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, ) @running = false @restarting = false @threads = {} @deployment_id = [: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
.client ⇒ Object
Returns the value of attribute client.
21 22 23 |
# File 'lib/opsicle/monitor/app.rb', line 21 def client @client end |
Instance Attribute Details
#deploy ⇒ Object (readonly)
Returns the value of attribute deploy.
18 19 20 |
# File 'lib/opsicle/monitor/app.rb', line 18 def deploy @deploy end |
#deployment_id ⇒ Object (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 |
#restarting ⇒ Object (readonly)
Returns the value of attribute restarting.
16 17 18 |
# File 'lib/opsicle/monitor/app.rb', line 16 def restarting @restarting end |
#running ⇒ Object (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 |
#restart ⇒ Object
76 77 78 |
# File 'lib/opsicle/monitor/app.rb', line 76 def restart @restarting = true end |
#start ⇒ Object
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(={}) = { error: nil, message: "" }.merge() @running = false wakey_wakey @screen.close @screen = nil # Ruby curses lib doesn't have closed?(), so we set to nil, just in case [:error] ? raise([:error]) : raise(QuitMonitor, [:message]) end |