external_service v0.5.1 ExternalService View Source
ExternalService handles all retry and circuit breaker logic for calls to external services.
Link to this section Summary
Types
Options used for controlling circuit breaker behavior. See the fuse docs for information about available fuse options
Functions
Given a fuse name and retry options execute a function handling any retry and circuit breaker
logic. ExternalService.start
must be run with the fuse name before using call
An async version of ExternalService.call
. Returns a Task
that may be used to retrieve the
result of the async call
A parallel, streaming version of ExternalService.call
A parallel, streaming version of ExternalService.call
A parallel, streaming version of ExternalService.call
. This function uses Elixir’s built-in
Task.async_stream/3
function and the description below is taken from there
Initializes a new fuse for a given service
Link to this section Types
fuse_not_found() :: {:error, {:fuse_not_found, fuse_name}}
fuse_options() :: [fuse_strategy: {:standard, pos_integer, pos_integer}, fuse_refresh: pos_integer]
Options used for controlling circuit breaker behavior. See the fuse docs for information about available fuse options.
retriable_function() :: (() -> retriable_function_result)
retriable_function_result() :: :retry | {:retry, reason :: any} | function_result :: any
retries_exhausted() :: {:error, {:retries_exhausted, reason :: any}}
Link to this section Functions
call(fuse_name, ExternalService.RetryOptions.t, retriable_function) :: error | function_result :: any
Given a fuse name and retry options execute a function handling any retry and circuit breaker
logic. ExternalService.start
must be run with the fuse name before using call.
The provided function can indicate that a retry should be performed by returning the atom
:retry
or a tuple of the form {:retry, reason}
, where reason
is any arbitrary term, or by
raising a RuntimeError
. Any other result is considered successful so the operation will not be
retried and the result of the function will be returned as the result of call
.
call_async(fuse_name, ExternalService.RetryOptions.t, retriable_function) :: Task.t
An async version of ExternalService.call
. Returns a Task
that may be used to retrieve the
result of the async call.
call_async_stream(Enumerable.t, fuse_name, (any -> retriable_function_result)) :: Enumerable.t
A parallel, streaming version of ExternalService.call
.
See call_async_stream/5
for full documentation.
call_async_stream(Enumerable.t, fuse_name, ExternalService.RetryOptions.t | async_opts :: list, (any -> retriable_function_result)) :: Enumerable.t
A parallel, streaming version of ExternalService.call
.
See call_async_stream/5
for full documentation.
call_async_stream(Enumerable.t, fuse_name, ExternalService.RetryOptions.t, async_opts :: list, (any -> retriable_function_result)) :: Enumerable.t
A parallel, streaming version of ExternalService.call
. This function uses Elixir’s built-in
Task.async_stream/3
function and the description below is taken from there.
Returns a stream that runs the given function function
concurrently on each
item in enumerable
.
Each enumerable
item is passed as argument to the given function function
and processed by its own task. The tasks will be linked to the current
process, similarly to async/1
.
start(fuse_name, fuse_options) :: :ok
Initializes a new fuse for a given service.