TN Reprocessing failed delivery tasks in batch

Currently, we have a schedule service to restart all the failed delivery tasks in TN. Basically, I want to only have 1 service thread for restarting all the failed tasks. Because if I loop through the failed tasks and call wm.tn.task:restartTask, it will execute all these failed tasks simultaneously. I only want to execute 1 at a time.

Is this possible and have anyone done this before…??

Thanks,
YLO

Just an idea:

-get task id’s that failed
-loop over task id’s
—call wm.tn.task:restartTask
—sleep a few seconds
-endloop