Class: Scales::Worker::Status
- Inherits:
-
Object
- Object
- Scales::Worker::Status
- Defined in:
- lib/scales-worker/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.
-
#log_path ⇒ Object
readonly
Returns the value of attribute log_path.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(address, port = nil) ⇒ Status
constructor
A new instance of Status.
- #put_response_in_queue!(response) ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
- #took_request_from_queue!(job) ⇒ Object
Constructor Details
#initialize(address, port = nil) ⇒ Status
Returns a new instance of Status.
7 8 9 10 11 12 13 14 |
# File 'lib/scales-worker/status.rb', line 7 def initialize address, port = nil @id = SecureRandom.hex(8) @key = "scales_worker_#{@id}" @address, @port = address.to_s, port.to_s @log_path = "log/scales_worker.#{@id}.log" @logger = Logger.new(Scales.env == "test" ? STDOUT : @log_path) @redis = Scales::Storage::Sync.new_connection! end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
5 6 7 |
# File 'lib/scales-worker/status.rb', line 5 def address @address end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/scales-worker/status.rb', line 5 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/scales-worker/status.rb', line 5 def key @key end |
#log_path ⇒ Object (readonly)
Returns the value of attribute log_path.
5 6 7 |
# File 'lib/scales-worker/status.rb', line 5 def log_path @log_path end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/scales-worker/status.rb', line 5 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/scales-worker/status.rb', line 5 def port @port end |
Instance Method Details
#put_response_in_queue!(response) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/scales-worker/status.rb', line 59 def put_response_in_queue!(response) data = { :id => response[1]['scales.id'], :worker_id => @id, :type => "worker_put_response_in_queue", :path => response[1]['PATH_INFO'], :method => response[1]['REQUEST_METHOD'], :status => response[0] } json = JSON.generate(data) @redis.publish("scales_monitor_events", json) end |
#start! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/scales-worker/status.rb', line 16 def start! data = { :id => @id, :key => @key, :type => "worker_started", :spawned_at => Time.now.to_i, :env => Scales.env, :ip => @address, :port => @port } json = JSON.generate(data) @redis.set(@key, json) @redis.publish("scales_monitor_events", json) @already_stopped = false end |
#stop! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/scales-worker/status.rb', line 33 def stop! return if @already_stopped data = { :id => @id, :key => @key, :type => "worker_stopped" } json = JSON.generate(data) @redis.del(@key) @redis.publish("scales_monitor_events", json) @already_stopped = true end |
#took_request_from_queue!(job) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/scales-worker/status.rb', line 47 def took_request_from_queue!(job) data = { :id => job['scales.id'], :worker_id => @id, :type => "worker_took_request_from_queue", :path => job['PATH_INFO'], :method => job['REQUEST_METHOD'] } json = JSON.generate(data) @redis.publish("scales_monitor_events", json) end |