Effect CommunityEC
Effect Community3y ago
7 replies
Thr1ve

Replicating Retry Strategy: Specific Errors, Delay, and Maximum Attempts

I'm trying to replicate an existing retry strategy that looks like:

* only retry if the error matches specific error/s (otherwise fail)
* begin with a delay of startDelay ms between retries
* double the delay each retry attempt up to a max of maxDelay ms
* retry a maximum of 5 times

I wasn't able to figure it out by looking at the docs, but I did find Composing Retry Methods retryN retryWhile with part of what I think I need.

So, now what I have is:

const startDelay = 200
const maxDelay = 500

const retryPolicy = pipe(
  Schedule.intersect(
    Schedule.linear(startDelay).pipe(Schedule.modifyDelay(Duration.max(maxDelay))),
    Schedule.recurs(5)
  ),
  Schedule.whileInput(
    (error: ParsedArangoError) =>
      error._tag === 'LockTimeout' ||
      error._tag === 'ConflictDetected' ||
      error._tag === 'TransactionNotFound'
  )
);


Struggling with the Schedule.linear part. I think Schedule.linear is correct, but I'm not sure how to properly prevent it from going above maxDelay. The above code seems to just make it delay 500 ms between each retry. 🤔
Was this page helpful?