kamui/retriable

Should the `on` argument to `with_context` be additive?

rspeicher opened this issue · 1 comments

Assume the following context definition:

  c.contexts[:mysql] = {
    tries: 10,
    multiplier: 2.5,
    on: Mysql::DeadlockException
  }

When using the context and providing an on parameter, I first assumed it would be added to the list of exceptions handled by the context. Instead, it overwrites:

Retriable.with_context(:mysql, on: SomeOtherException) do
  # This will only retry on `SomeOtherException`!
end

At the very least, it might warrant a callout in the README.

This is the only parameter I'd expect to behave in an additive way. All of the others make sense as overrides to me.

sunny commented

From my point of view if makes more sense to have it overwrite the context definition. Making it additive would make it harder to replace the exception and possibily break some code that relies on it being replaced.

A workaround here could be sharing that list in a constant for example:

MYSQL_RETRIES = [Mysql::DeadlockException]

Retriable.configure do |c|
  c.contexts[:mysql] = {
    tries: 10,
    multiplier: 2.5,
    on: MYSQL_RETRIES
  }
end

And reuse it:

Retriable.with_context(:mysql, on: [MYSQL_RETRIES*, SomeOtherException]) do
  # …
end