Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: "Reset time" option for tries #32

Closed
skrabadiloseidon opened this issue Nov 16, 2020 · 4 comments
Closed

Feature: "Reset time" option for tries #32

skrabadiloseidon opened this issue Nov 16, 2020 · 4 comments

Comments

@skrabadiloseidon
Copy link

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.

@nfedyashev
Copy link
Owner

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

@skrabadiloseidon
Copy link
Author

skrabadiloseidon commented Nov 16, 2020

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

@nfedyashev
Copy link
Owner

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

@skrabadiloseidon
Copy link
Author

Thanks i will try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants