Dinnerbone / mcstatus

A Python class for checking the status of an enabled Minecraft server
http://dinnerbone.com/minecraft/tools/status/
1.11k stars 146 forks source link

Merge retry logic into a single decorator #186

Closed ItsDrike closed 2 years ago

ItsDrike commented 2 years ago

Closes #139

As discussed in the issue, this introduces a retry decorator which will automate the logic of retrying the code for several specified amount of tries until the function was successful or if the function failed in each of the tries, raise the last exception that occurred.

ItsDrike commented 2 years ago

The _retry_X methods that I've used are admittedly a bit weird to see and I'm opened for suggestions on better names or even completely different better approaches.

I've done this because we only want to repeat a certain part of those functions and it doesn't make sense to decorate the whole function and re-run everything in it. Not only would that be inefficient, it often wouldn't even be what's desired and may cause issues.