aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh <[email protected]>2020-08-29 13:12:07 +1000
committerRapptz <[email protected]>2020-09-24 02:17:54 -0400
commitb3e0752af48a25933bcb8fe7efaf78eedc1977e6 (patch)
tree3d881f23934e1dd6f4083863cc375a708ec8a198
parentFix bug with Guild.by_category not showing some channels (diff)
downloaddiscord.py-b3e0752af48a25933bcb8fe7efaf78eedc1977e6.tar.xz
discord.py-b3e0752af48a25933bcb8fe7efaf78eedc1977e6.zip
[tasks] Don't update _next_iteration on retry
-rw-r--r--discord/ext/tasks/__init__.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py
index e54573ef..b4e8f2b2 100644
--- a/discord/ext/tasks/__init__.py
+++ b/discord/ext/tasks/__init__.py
@@ -68,6 +68,7 @@ class Loop:
raise ValueError('count must be greater than 0 or None.')
self.change_interval(seconds=seconds, minutes=minutes, hours=hours)
+ self._last_iteration_failed = False
self._last_iteration = None
self._next_iteration = None
@@ -88,18 +89,22 @@ class Loop:
backoff = ExponentialBackoff()
await self._call_loop_function('before_loop')
sleep_until = discord.utils.sleep_until
+ self._last_iteration_failed = False
self._next_iteration = datetime.datetime.now(datetime.timezone.utc)
try:
await asyncio.sleep(0) # allows canceling in before_loop
while True:
- self._last_iteration = self._next_iteration
- self._next_iteration = self._get_next_sleep_time()
+ if not self._last_iteration_failed:
+ self._last_iteration = self._next_iteration
+ self._next_iteration = self._get_next_sleep_time()
try:
await self.coro(*args, **kwargs)
+ self._last_iteration_failed = False
now = datetime.datetime.now(datetime.timezone.utc)
if now > self._next_iteration:
self._next_iteration = now
except self._valid_exception as exc:
+ self._last_iteration_failed = True
if not self.reconnect:
raise
await asyncio.sleep(backoff.delay())