Respect Telegram's throttle requests while generating timelapses #179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been having occasional hiccups when it came to timelapses. I've been getting errors like:
Jun 22 23:24:38 fluiddpi python[549]: telegram.error.RetryAfter: Flood control exceeded. Retry in 13.0 seconds
so… I decided to add a kinda proper handling of this error instead of the naive implementation I've commited some time ago.This implementation is sort-of generic and may be transplanted to other parts of code if you wish so (I haven't seen the need so far though). The
retryable_notification
is almost a decorator as it needs a callable/lambda as an argument and repeatedly tries to execute it until one of the conditions is met. The first argument decides how persistent should this mechanism be:if required is True
then it will try sending the message no matter what and in case of a fail will block for the requested number of seconds.if required is False
then it may proactively block the request at all if it knows that the required amount of time has not passed yet, but will not block the rest of the code.As you can see in the screencast below the messages are kinda choppy, but it's close to the best what we can do without actually slowing the timelapse generation.
https://user-images.githubusercontent.com/322405/175297031-3380da45-7cc7-4942-8efd-e1f7d06d4f96.mp4
Hope you like it & have a wonderful day
Paweł