Automatic rerun for failed tests

I think this new Smarter Testing feature that is in Beta may be a better fit for your use case, did you check it out already?