Class: Executer::Client
- Inherits:
-
Object
- Object
- Executer::Client
- Defined in:
- lib/executer/client.rb
Instance Attribute Summary collapse
-
#redis_1 ⇒ Object
readonly
Returns the value of attribute redis_1.
-
#redis_2 ⇒ Object
readonly
Returns the value of attribute redis_2.
Instance Method Summary collapse
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #log(message) ⇒ Object
- #run(options) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/executer/client.rb', line 6 def initialize(config) if File.exist?(config) = YAML.load(File.read(config)) redis_url = ['redis'] @logger = Logger.new(['log'] || '/var/log/executer.log') else redis_url = config @logger = Logger.new('/var/log/executer.log') end @redis_1 = Redis.connect(:url => "redis://#{redis_url}") @redis_2 = Redis.connect(:url => "redis://#{redis_url}") end |
Instance Attribute Details
#redis_1 ⇒ Object (readonly)
Returns the value of attribute redis_1.
4 5 6 |
# File 'lib/executer/client.rb', line 4 def redis_1 @redis_1 end |
#redis_2 ⇒ Object (readonly)
Returns the value of attribute redis_2.
4 5 6 |
# File 'lib/executer/client.rb', line 4 def redis_2 @redis_2 end |
Instance Method Details
#log(message) ⇒ Object
41 42 43 |
# File 'lib/executer/client.rb', line 41 def log() @logger.info("CLIENT: #{}") end |
#run(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/executer/client.rb', line 19 def run() id = [:id] = Yajl::Encoder.encode() success = nil Timeout.timeout(60*60) do @redis_1.subscribe("executer:response:#{id}") do |on| on.subscribe do |channel, subscriptions| log("Queuing: #{.inspect}") @redis_2.rpush "executer:request", end on. do |channel, | success = log("Finished: #{.inspect}") @redis_1.unsubscribe end end end success end |