Class: Autoscale::Agent::WorkerDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/autoscale/agent/worker_dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tokenObject (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

#dispatchObject



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