retort v1.3.0 Retort.Server.Generic.RPC

A request, its meta data and its response for RabbitMQ. Lke a Plug.Conn, but for RPC.

Any pure functions that write back to the Retort.Server.Generic.RPC.t can be in this module. Any code with side-effects, such as Logger or Repo calls should go in Retort.Server.Generic.

Summary

Functions

Adds key to assigns with value

Extracts an Alembic.Document.t from request.decoded.params and assigns it to assigns.document

Decodes the request.encoded to an Retort.Request and puts it in request.decoded

Makes sure that the keys in the request.decoded.params are underscored as required by Alembic

Converts the :basic_deliver arguments passed to Retort.Server.Generic.handle_info/2 by AMQP to a t

Halts the rpc after setting the response.decoded to the output of function

Checks that the response.decoded.id matches the meta.correlation_id

Converts the request.decoded to a response.decoded with the same id

Times duration of function and puts that timing information in timing section of t

Types

t()
t() :: %Retort.Server.Generic.RPC{assigns: %{optional(atom) => any}, halted: boolean, meta: %{correlation_id: binary, delivery_tag: term, reply_to: term} | nil, request: %{decoded: Retort.Request.t | nil, encoded: binary}, response: %{decoded: Retort.Response.t | nil, encoded: binary | nil}, timing: %{ending_monotonic_time: integer | nil, starting_monotonic_time: integer | nil}}

Functions

assign(rpc, key, value)
assign(t, key :: any, value :: any) :: t

Adds key to assigns with value

assign_document(r_p_c, action)
assign_document(t, atom) :: t

Extracts an Alembic.Document.t from request.decoded.params and assigns it to assigns.document.

If there is an error extracting the document, the response.decoded is set to an error Alembic.Document.t and the t is halted.

decode_request(r_p_c)
decode_request(t) :: t

Decodes the request.encoded to an Retort.Request and puts it in request.decoded.

If there is an error, the response.decoded is set to an error Alembic.Document.t and the t is halted.

format_request_params(r_p_c)
format_request_params(t) :: t

Makes sure that the keys in the request.decoded.params are underscored as required by Alembic

from_basic_deliver(arg, )
from_basic_deliver({:basic_deliver, binary, map}, Retort.Server.Generic.t) :: t

Converts the :basic_deliver arguments passed to Retort.Server.Generic.handle_info/2 by AMQP to a t.

halt(rpc, function)

Halts the rpc after setting the response.decoded to the output of function

match_correlation_id(r_p_c)
match_correlation_id(%Retort.Server.Generic.RPC{assigns: term, halted: true, meta: term, request: term, response: term, timing: term}) :: t
match_correlation_id(%Retort.Server.Generic.RPC{assigns: term, halted: false, meta: %{:correlation_id => binary, optional(any) => any}, request: %{decoded: Retort.Response.t}, response: term, timing: term}) :: t

Checks that the response.decoded.id matches the meta.correlation_id

request_to_response(r_p_c)
request_to_response(t) :: t

Converts the request.decoded to a response.decoded with the same id

time(r_p_c, function)
time(t, (t -> t)) :: t

Times duration of function and puts that timing information in timing section of t

The timing.starting_monotonic_time will be set on the t passed to function. The t returned by function will have timing.ending_monotonic_time set on it before being returned.