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 34 35 36 37 38 39 |
# 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) if @deployment_id # `deploy`, `chef-update`, `execute-recipes` command, which is no-tty compatible so these can be automated via cron, etc. @deploy = Opsicle::Deployment.new(@deployment_id, App.client) else # `monitor` command, which requires a TTY. raise "Monitor requires a TTY." unless $stdout.tty? end 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
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/opsicle/monitor/app.rb', line 88 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
84 85 86 |
# File 'lib/opsicle/monitor/app.rb', line 84 def restart @restarting = true end |
#start ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/opsicle/monitor/app.rb', line 41 def start begin @running = true if $stdout.tty? 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 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
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/opsicle/monitor/app.rb', line 73 def stop(={}) = { error: nil, message: "" }.merge() @running = false wakey_wakey @screen.close unless @screen.nil? @screen = nil # Ruby curses lib doesn't have closed?(), so we set to nil, just in case [:error] ? raise([:error]) : raise(QuitMonitor, [:message]) end |