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

Link to this type fuse_blown() View Source
fuse_blown() :: {:error, {:fuse_blown, fuse_name}}
Link to this type fuse_name() View Source
fuse_name() :: atom
Link to this type fuse_not_found() View Source
fuse_not_found() :: {:error, {:fuse_not_found, fuse_name}}
Link to this type fuse_options() View Source
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.

Link to this type retriable_function() View Source
retriable_function() :: (() -> retriable_function_result)
Link to this type retriable_function_result() View Source
retriable_function_result() :: :retry | {:retry, reason :: any} | function_result :: any
Link to this type retries_exhausted() View Source
retries_exhausted() :: {:error, {:retries_exhausted, reason :: any}}

Link to this section Functions

Link to this function call(fuse_name, retry_opts \\ %ExternalService.RetryOptions{}, function) View Source

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.

Link to this function call_async(fuse_name, retry_opts \\ %ExternalService.RetryOptions{}, function) View Source

An async version of ExternalService.call. Returns a Task that may be used to retrieve the result of the async call.

Link to this function call_async_stream(enumerable, fuse_name, function) View Source

A parallel, streaming version of ExternalService.call.

See call_async_stream/5 for full documentation.

Link to this function call_async_stream(enumerable, fuse_name, retry_opts, function) View Source
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.

Link to this function call_async_stream(enumerable, fuse_name, retry_opts, async_opts, function) View Source
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.

Link to this function start(fuse_name, fuse_options \\ []) View Source
start(fuse_name, fuse_options) :: :ok

Initializes a new fuse for a given service.