nfedyashev/retryable

Feature: "Reset time" option for tries

skrabadiloseidon opened this issue · 4 comments

Some kind of "reset time" option for tries would be nice.
When this option is set it should reset the tries count back to 0.
Why could this be useful?

I wrote a script that connects to a mysql server, sometimes i need to restart the server, so i wrapped my code with this gem.
When the server is restarting, a exception is raised, then it waits 10 seconds, the server is online again end everything is fine,
except i restart the server multiple times a week then the tries count is reached an the script stops.
but if i could define a timeout after the tries count is resetted this would work perfect.

sorry for my bad english, i hope you can understand what i mean.

I'm not sure I fully understand your message.
Can you provide some code samples?

I try to explain it with art of pseudo code:

loop do
  Retryable.retryable(tries: 3, sleep: 10) times do
    mysql.insert("data")
  end
end
  • I run the code, now i restart the mysql server, the mysql.insert code raises an exception => tries +1
  • The server ist back online, mysql.insert ist working again
  • Next day in need to restart the mysql server again => mysql.insert exception => tries +1
  • Next day the same=> tries +1 => tries is now 3 => script ends

Now my idea: An option to tell retryable: retry this 3 times. after x seconds reset tries back to 0, so i have 3 tries again.

Failure example: Mysql server is restarted in 10 seconds => short problem, tries resetted, script working again
Failure example: Mysql server crashed because hdd full => long problem, more then x tries in x seconds => no reset, script ends and raises final exception

Wouldn't a combination of :not option + retries count comparison solve this use case?

https://github.com/nfedyashev/retryable#matching-error-messages - that's how you can check how many tries did it make.
If it is above a certain threshold raise a custom exception that's listed in :not array - https://github.com/nfedyashev/retryable#specify-exceptions-where-a-retry-should-not-be-performed

Thanks i will try it.