Java – akka: how to schedule retry failures when the delay interval is extended?
What is a good way for an actor to try again and fail, but the time interval between retries is getting longer and longer? Suppose I want the actor to try again in 15 seconds and 30 seconds, then every minute will be limited
This is what I came up with:
>The method of the actor executing the actual work is an optional retryinfo parameter. If it exists, the number contained will be retrying. When it fails, the actor will send a new scheduleretrymessage to retrycount 1, throw a runtimeException > another actor, supervise the worker actor, and use the new oneforonestrategy (- 1, duration. Inf()) to return resume as its instruction, The actor has no status, so resume should be OK > when receiving the scheduleretrymessage, the actor will
>If retrycount < Max_ Restries: use akka's scheduler to schedule retrymessage after the required delay > Other: finally give up and send a message to another actor error report
Is this a good solution or is there a better way?
Solution
You can have an actor in charge of starting workers The prompt in the document is to declare a router of size 1 for the staff The supervisor will track the number of retries and schedule messages to staff as needed
Even if you will create another layer of actors, this seems clearer to me because you exclude the supervision function from the staff Ideally, you can have this 1 supervisor on N staff, but I think you must use life cycle monitoring to get failure from child actors In this case, you only need to keep the map of [actorref, int] to track the retry times of all regulated personnel The supervision policy will be restored, but if you reach the maximum number of retries, you can send poison to the guilty actorref