Class: Appfuel::Service::Worker

Inherits:
Object
  • Object
show all
Includes:
Application::AppContainer, Application::Dispatcher, Sneakers::Worker
Defined in:
lib/appfuel/service/worker.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(klass) ⇒ Object



9
10
11
# File 'lib/appfuel/service/worker.rb', line 9

def inherited(klass)
  stage_class_for_registration(klass)
end

Instance Method Details

#publish_rpc(request, response) ⇒ Nil

Publish a response for the rpc request.

Parameters:

  • request (MsgRequest)
  • respons (Appfuel::Response)

Returns:

  • (Nil)


40
41
42
43
44
45
46
47
48
# File 'lib/appfuel/service/worker.rb', line 40

def publish_rpc(request, response)
  options = {
    correlation_id: request.correlation_id,
    routing_key: request.reply_to,
    headers: { "action_route" => request.action_route }
  }
  publish(response.to_json, options)
  nil
end

#work_with_params(msg, delivery_info, properties) ⇒ Appfuel::Response

Sneakers worker hook to handle messages from RabbitMQ

Parameters:

  • msg (String)

    JSON string of inputs

  • delivery_info (Bunny::Delivery::Info)
  • properties (Bunny::MessageProperties)

Returns:

  • (Appfuel::Response)


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/appfuel/service/worker.rb', line 21

def work_with_params(msg, delivery_info, properties)
  container = app_container
  request   = create_request(msg, delivery_info, properties)
  response  = dispatch(request, container)

  if request.rpc?
    publish_rpc(request, response)
  end

  ack!
  response
end