Class: Autoscale::Agent::WorkerDispatcher
- Inherits:
-
Object
- Object
- Autoscale::Agent::WorkerDispatcher
- Defined in:
- lib/autoscale/agent/worker_dispatcher.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #dispatch ⇒ Object
-
#initialize(token, &block) ⇒ WorkerDispatcher
constructor
A new instance of WorkerDispatcher.
Constructor Details
#initialize(token, &block) ⇒ WorkerDispatcher
Returns a new instance of WorkerDispatcher.
6 7 8 9 10 |
# File 'lib/autoscale/agent/worker_dispatcher.rb', line 6 def initialize(token, &block) @id = token.each_char.take(7).join @token = token @block = block end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/autoscale/agent/worker_dispatcher.rb', line 4 def token @token end |
Instance Method Details
#dispatch ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/autoscale/agent/worker_dispatcher.rb', line 12 def dispatch if (value = @block.call) body = MultiJson.dump(Time.now.to_i => value) response = Request.dispatch(body, token: @token) unless response.is_a?(Net::HTTPOK) error "Failed to dispatch (#{response.code}) #{response.body}" end else error "Failed to calculate worker information (nil)" end end |