retort v2.7.0 Retort.Server.Generic.RPC View Source

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.

Link to this section 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

Link to this section Types

Link to this type t() View Source
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}}

Link to this section Functions

Link to this function assign(rpc, key, value) View Source
assign(t(), key :: any(), value :: any()) :: t()

Adds key to assigns with value

Link to this function assign_document(rpc, action) View Source
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.

Link to this function decode_request(rpc) View Source
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.

Link to this function format_request_params(rpc) View Source
format_request_params(t()) :: t()

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

Link to this function from_basic_deliver(arg, _) View Source
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.

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

Link to this function match_correlation_id(rpc) View Source
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()
match_correlation_id(%Retort.Server.Generic.RPC{assigns: term(), halted: true, meta: term(), request: term(), response: term(), timing: term()}) :: t()

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

Link to this function request_to_response(rpc) View Source
request_to_response(t()) :: t()

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

Link to this function time(rpc, function) View Source
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.