What is a good way of having an actor try something again on failure, but with growing time intervals between the retries? Let's say I want the actor to try again after 15 seconds, then 30 seconds, then every minute for a limited number of times.
Here's what I've come up with:
- the method of the actor that performs the actual work has an optional
RetryInfoparameter that, if present, contains the number of the retry we are currently in - on failure, the actor will send itself a new
ScheduleRetryMessagewithretryCount + 1, then throw a RuntimeException - another actor supervises the worker actor, using
new OneForOneStrategy(-1, Duration.Inf()returningResumeas its Directive. The actor has no state, soResumeshould be OK - on receiving the
ScheduleRetryMessage, the actor will- if
retryCount < MAX_RETRIES: use Akka's scheduler to schedule sending aRetryMessageafter the desired delay - else: finally give up, sending a message to another actor for error reporting
- if
Is this a good solution or is there a better approach?