Class: Scales::Server::Status
- Inherits:
-
Object
- Object
- Scales::Server::Status
- Defined in:
- lib/scales-server/status.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(address, port) ⇒ Status
constructor
A new instance of Status.
- #put_request_in_queue!(job) ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
- #took_response_from_queue!(response) ⇒ Object
Constructor Details
#initialize(address, port) ⇒ Status
Returns a new instance of Status.
7 8 9 10 11 |
# File 'lib/scales-server/status.rb', line 7 def initialize address, port @id = SecureRandom.hex(8) @key = "scales_server_#{@id}" @address, @port = address.to_s, port.to_s end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
5 6 7 |
# File 'lib/scales-server/status.rb', line 5 def address @address end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/scales-server/status.rb', line 5 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/scales-server/status.rb', line 5 def key @key end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/scales-server/status.rb', line 5 def port @port end |
Instance Method Details
#put_request_in_queue!(job) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/scales-server/status.rb', line 40 def put_request_in_queue!(job) data = { :id => job['scales.id'], :server_id => @id, :type => "server_put_request_in_queue", :path => job['PATH_INFO'], :method => job['REQUEST_METHOD'] } json = JSON.generate(data) Storage::Sync.connection.publish("scales_monitor_events", json) end |
#start! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/scales-server/status.rb', line 13 def start! data = { :id => @id, :key => @key, :type => "server_started", :spawned_at => Time.now.to_i, :env => Scales.env, :ip => @address, :port => @port } json = JSON.generate(data) Storage::Sync.connection.set(@key, json) Storage::Sync.connection.publish("scales_monitor_events", json) end |
#stop! ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/scales-server/status.rb', line 29 def stop! data = { :id => @id, :key => @key, :type => "server_stopped" } json = JSON.generate(data) Storage::Sync.connection.del(@key) Storage::Sync.connection.publish("scales_monitor_events", json) end |
#took_response_from_queue!(response) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/scales-server/status.rb', line 52 def took_response_from_queue!(response) data = { :id => response[1]['scales.id'], :server_id => @id, :type => "server_took_response_from_queue", :path => response[1]['PATH_INFO'], :method => response[1]['REQUEST_METHOD'], :status => response[0] } json = JSON.generate(data) Storage::Sync.connection.publish("scales_monitor_events", json) end |