Task.Supervisor.start_child is not taking the max_seconds delay for restart

            fn ->
              verify_customer(current_user, first_pension)
            restart: :transient,
            max_restarts: 3,
            max_seconds: 1800

I am using the above code for background task. My restart is working fine but the max_restarts: 3 is happening immendiately and not as per the max_seconds: 1800. Looks like max_seconds: 1800 is not working.

Any idea, please suggest.

Restarts always happen immediately. max_seconds defines the timeframe in which max_restarts is counted. The supervisor will tolerate at max 3 restarts within a timeframe of 1800 seconds.

Thanks, so how to do a restart after every 30 mins maximum upto 3 times.
I need the background task to wait for 30 mins (1800 secs) and then again retry.

You can’t with supervisors. That’s simply not what they’re built for. You’ll need to manage restarts another way.

OK thanks again. is there any other way of doing restart of a background task as per my above requirement?

Well, you can check out Parent or director which should allow you to define such behaviour. Alternatively you can implement your own supervisor.

1 Like

There is also gen_retry which can help for this.

1 Like

Thanks all for your guidance, I will try these options and update what works for me.

gen_retry works for me.
Thanks a lot.