Tesla.Middleware.Fuse (tesla v1.4.2) View Source
Circuit Breaker middleware using fuse.
Remember to add {:fuse, "~> 2.4"}
to dependencies (and :fuse
to applications in mix.exs
)
Also, you need to recompile tesla after adding :fuse
dependency:
mix deps.clean tesla
mix deps.compile tesla
Examples
defmodule MyClient do
use Tesla
plug Tesla.Middleware.Fuse,
opts: {{:standard, 2, 10_000}, {:reset, 60_000}},
keep_original_error: true,
should_melt: fn
{:ok, %{status: status}} when status in [428, 500, 504] -> true
{:ok, _} -> false
{:error, _} -> true
end
end
Options
:name
- fuse name (defaults to module name):opts
- fuse options (see fuse docs for reference):keep_original_error
- boolean to indicate if, in case of melting (based onshould_melt
), it should return the upstream's error or the fixed one{:error, unavailable}
. It's false by default, but it will be true in2.0.0
version:should_melt
- function to determine if response should melt the fuse
SASL logger
fuse library uses SASL (System Architecture Support Libraries).
You can disable its logger output using:
config :sasl, sasl_error_logger: :false
Read more at jlouis/fuse#32 and jlouis/fuse#19.