mediative / eigenflow

ETL orchestration platform with recoverability and process monitoring features
https://mediative.github.io/eigenflow/
Apache License 2.0
9 stars 4 forks source link

Implement exponential backoff retry strategy #8

Closed yawaramin closed 6 years ago

yawaramin commented 8 years ago
yawaramin commented 8 years ago

One possible way to do this is to redefine ExecutionPlan#retryStrategy to be a stream of retry descriptions (Retry objects); we retry as long as there are more elements in the stream, obeying the described interval. Then the exponential backoff strategy could be something like

object Retry {
  /**
  Returns a stream of retry descriptions following the exponential backoff strategy.
  */
  def exponentialBackoff(initialInterval: FiniteDuration, increaseFactor: Int, attempts: Int) =
    Stream.iterate(Retry(initialInterval), attempts) { retry =>
      retry.copy(interval = increaseFactor * retry.interval)
    }

  val noRetry = Stream.empty
}
yawaramin commented 8 years ago

Of course, with this re-definition of ExecutionPlan#retryStrategy, the implication is that Retry#attempts is no longer needed and a retry description becomes semantically just an interval to wait: case class Retry(interval: FiniteDuration) extends AnyVal. The number of attempts is captured by the length of the retry strategy stream.