Skip to content

Commit

Permalink
fix: reset exponential backoff after task runs successfully in tasks …
Browse files Browse the repository at this point in the history
…extension (Pycord-Development#2700)

* [tasks] reset exponential backoff after task runs successfully

The current behaviour of the _loop method (when the reconnect
attribute is set to True) is to have the same ExponentialBackoff
instance for all of its lifetime. A task that has failed n times
over its life-time will thus wait 2**n seconds before retrying, no
matter how many successful instances of happened between the failures.

With this commit, the behaviour is to reset the exponential backoff
after a succesful execution of the task, so that the backoff only
takes place after successive failures.

* Update CHANGELOG.md

Signed-off-by: DaBlumer <[email protected]>

* Update CHANGELOG.md

Co-authored-by: JustaSqu1d <[email protected]>
Signed-off-by: DaBlumer <[email protected]>

---------

Signed-off-by: DaBlumer <[email protected]>
Co-authored-by: JustaSqu1d <[email protected]>
  • Loading branch information
DaBlumer and JustaSqu1d authored Jan 27, 2025
1 parent ad2ccad commit dbd9f1b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ These changes are available on the `master` branch, but have not yet been releas
- Fixed attachment metadata being set incorrectly in interaction responses causing the
metadata to be ignored by Discord.
([#2679](https://github.com/Pycord-Development/pycord/pull/2679))
- Fixed unexpected backoff behavior in the handling of task failures
([#2700](https://github.com/Pycord-Development/pycord/pull/2700)).

### Changed

Expand Down
1 change: 1 addition & 0 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None:
try:
await self.coro(*args, **kwargs)
self._last_iteration_failed = False
backoff = ExponentialBackoff()
except self._valid_exception:
self._last_iteration_failed = True
if not self.reconnect:
Expand Down

0 comments on commit dbd9f1b

Please sign in to comment.