johanhaleby / occurrent

Unintrusive Event Sourcing Library for the JVM
https://occurrent.org
120 stars 16 forks source link

Add support for handling final exception #136

Open johanhaleby opened 1 year ago

johanhaleby commented 1 year ago

Currently, you can do:

RetryStrategy
                .exponentialBackoff(Duration.ofSeconds(1), Duration.ofSeconds(5), 2.0)
                .maxAttempts(10)
                .onError { info, throwable -> println("somethign") }
                .execute(..)

But it would be nice to do something on "completion with failure", for example, to avoid avoid try/catch around the retry strategy. E.g.

RetryStrategy
                .exponentialBackoff(Duration.ofSeconds(1), Duration.ofSeconds(5), 2.0)
                .maxAttempts(10)
                .onError { info, throwable -> println("somethign") }
                .execute(..)
                .mapError(throwable -> // return a new throwable )

and/or:

RetryStrategy
                .exponentialBackoff(Duration.ofSeconds(1), Duration.ofSeconds(5), 2.0)
                .maxAttempts(10)
                .onError { info, throwable -> println("somethign") }
                .execute(..)
                .onCompletedWithError(throwable -> ) // Maybe add "onCompletedSuccessfully" or replace with common "onCompleted" method?

and/or:

RetryStrategy
                .exponentialBackoff(Duration.ofSeconds(1), Duration.ofSeconds(5), 2.0)
                .maxAttempts(10)
                .onError { info, throwable -> println("somethign") }
                .execute(..)
                .returnIfCompletedWithError(throwable -> "something else" ) // Move back to happy track (Better name needed)