Packages
ferricstore
0.4.2
0.11.14
0.11.12
0.11.11
0.11.10
0.11.9
0.11.8
0.11.7
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
0.9.1
0.9.0
0.8.0
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.0
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.2.0
0.1.0
FerricFlow durable workflows and queues with native-protocol storage, Raft durability, and Bitcask persistence.
Current section
Files
Jump to
Current section
Files
lib/ferricstore/fault_injection.ex
defmodule Ferricstore.FaultInjection do
@moduledoc false
@hook_key {__MODULE__, :hook}
@spec maybe_pause(atom(), map()) :: :ok | {:error, term()}
def maybe_pause(point, metadata \\ %{}) when is_atom(point) and is_map(metadata) do
case :persistent_term.get(@hook_key, nil) do
fun when is_function(fun, 2) -> normalize(fun.(point, metadata))
_other -> :ok
end
catch
kind, reason -> {:error, {:fault_injection_hook_failed, kind, reason}}
end
@doc false
@spec put_hook((atom(), map() -> term())) :: :ok
def put_hook(fun) when is_function(fun, 2) do
:persistent_term.put(@hook_key, fun)
:ok
end
@doc false
@spec clear_hook() :: :ok
def clear_hook do
:persistent_term.erase(@hook_key)
:ok
catch
:error, :badarg -> :ok
end
defp normalize(:ok), do: :ok
defp normalize({:error, _reason} = error), do: error
defp normalize(_other), do: :ok
end