lib/scales-worker/status.rb in scales-worker-0.0.1.beta.2 vs lib/scales-worker/status.rb in scales-worker-0.0.4

- old
+ new

@@ -1,15 +1,18 @@ module Scales module Worker class Status - attr_reader :key, :id, :address, :port + attr_reader :key, :id, :address, :port, :logger, :log_path def initialize address, port = nil - @id = SecureRandom.hex(8) - @key = "scales_worker_#{@id}" + @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 def start! data = { :id => @id, @@ -20,12 +23,12 @@ :ip => @address, :port => @port } json = JSON.generate(data) - Storage::Sync.connection.set(@key, json) - Storage::Sync.connection.publish("scales_monitor_events", json) + @redis.set(@key, json) + @redis.publish("scales_monitor_events", json) @already_stopped = false end def stop! return if @already_stopped @@ -34,12 +37,12 @@ :id => @id, :key => @key, :type => "worker_stopped" } json = JSON.generate(data) - Storage::Sync.connection.del(@key) - Storage::Sync.connection.publish("scales_monitor_events", json) + @redis.del(@key) + @redis.publish("scales_monitor_events", json) @already_stopped = true end def took_request_from_queue!(job) data = { @@ -48,11 +51,11 @@ :type => "worker_took_request_from_queue", :path => job['PATH_INFO'], :method => job['REQUEST_METHOD'] } json = JSON.generate(data) - Storage::Sync.connection.publish("scales_monitor_events", json) + @redis.publish("scales_monitor_events", json) end def put_response_in_queue!(response) data = { :id => response[1]['scales.id'], @@ -61,10 +64,10 @@ :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) + @redis.publish("scales_monitor_events", json) end end end \ No newline at end of file