EasyRpc.Pipeline (EasyRpc v1.0.0)

Copy Markdown View Source

Builds and executes a middleware pipeline for RPC calls.

A pipeline is an ordered list of {plug_module, opts} tuples. Plugs are composed inside-out — the first plug in the list is the outermost middleware and the last plug is the innermost.

Default pipeline

[Retry, Logger, NodeSelector, Executor, ErrorHandler]

This replicates the behaviour of the original RpcCall.

Summary

Functions

Executes a pipeline by composing the plugs into a chain and calling it with the given context.

Default pipeline that mirrors the original RpcCall behaviour.

Convenience: builds the default pipeline, runs it, and returns the context.

Extracts the final result from a pipeline context.

Convenience: creates a context, runs the pipeline, and extracts the result.

Types

plug_entry()

@type plug_entry() :: {module(), term()}

t()

@type t() :: [plug_entry()]

Functions

call(pipeline, ctx)

@spec call(t(), EasyRpc.Context.t()) :: EasyRpc.Context.t()

Executes a pipeline by composing the plugs into a chain and calling it with the given context.

The returned context contains the final state — inspect ctx.result, ctx.error, and ctx.halted after calling.

default()

@spec default() :: t()

Default pipeline that mirrors the original RpcCall behaviour.

Order (outermost → innermost):

  1. ErrorHandler — normalises result/error on the context
  2. Retry — wraps the entire call, re-executes on failure
  3. NodeSelector — picks a target node
  4. Logger — logs before and after each attempt
  5. Executor — calls :erpc.call

execute(ctx)

@spec execute(EasyRpc.Context.t()) :: EasyRpc.Context.t()

Convenience: builds the default pipeline, runs it, and returns the context.

extract_result(ctx, config)

@spec extract_result(EasyRpc.Context.t(), EasyRpc.WrapperConfig.t()) :: term()

Extracts the final result from a pipeline context.

Handles both bare mode (raises on error) and safe mode (returns {:ok, result} | {:error, error}).

run(config, function, args, pipeline \\ default())

@spec run(EasyRpc.WrapperConfig.t(), atom(), list(), t()) :: term()

Convenience: creates a context, runs the pipeline, and extracts the result.

This is the primary entry point used by code-generated wrapper functions.