safwank / ElixirRetry

Simple Elixir macros for linear retry, exponential backoff and wait with composable delays
Other
441 stars 32 forks source link

Retry on *any* exception, forever #66

Open krisleech opened 1 month ago

krisleech commented 1 month ago

We are consuming messages from Kafka using Broadway.

Since Broadway will always ack the message we need to handle retry ourselves.

If there is any error we want to retry indefinitely.

This is the code we have:

retry_while with: exponential_backoff(1000) |> cap(10_000) do
  try do
    raise "BOOM"
  rescue
    exception ->
      report(exception, __STACKTRACE__)
      {:cont, nil}
   else
      _ -> {:halt, nil}
  end
end

I assume if I don't use Stream.take then it will retry forever?

Any additional thoughts on this approach?

Thanks!