[tasks] Don't update _next_iteration on retry
This commit is contained in:
parent
4203e7a5a8
commit
6baacb2c23
@ -68,6 +68,7 @@ class Loop:
|
|||||||
raise ValueError('count must be greater than 0 or None.')
|
raise ValueError('count must be greater than 0 or None.')
|
||||||
|
|
||||||
self.change_interval(seconds=seconds, minutes=minutes, hours=hours)
|
self.change_interval(seconds=seconds, minutes=minutes, hours=hours)
|
||||||
|
self._last_iteration_failed = False
|
||||||
self._last_iteration = None
|
self._last_iteration = None
|
||||||
self._next_iteration = None
|
self._next_iteration = None
|
||||||
|
|
||||||
@ -88,18 +89,22 @@ class Loop:
|
|||||||
backoff = ExponentialBackoff()
|
backoff = ExponentialBackoff()
|
||||||
await self._call_loop_function('before_loop')
|
await self._call_loop_function('before_loop')
|
||||||
sleep_until = discord.utils.sleep_until
|
sleep_until = discord.utils.sleep_until
|
||||||
|
self._last_iteration_failed = False
|
||||||
self._next_iteration = datetime.datetime.now(datetime.timezone.utc)
|
self._next_iteration = datetime.datetime.now(datetime.timezone.utc)
|
||||||
try:
|
try:
|
||||||
await asyncio.sleep(0) # allows canceling in before_loop
|
await asyncio.sleep(0) # allows canceling in before_loop
|
||||||
while True:
|
while True:
|
||||||
self._last_iteration = self._next_iteration
|
if not self._last_iteration_failed:
|
||||||
self._next_iteration = self._get_next_sleep_time()
|
self._last_iteration = self._next_iteration
|
||||||
|
self._next_iteration = self._get_next_sleep_time()
|
||||||
try:
|
try:
|
||||||
await self.coro(*args, **kwargs)
|
await self.coro(*args, **kwargs)
|
||||||
|
self._last_iteration_failed = False
|
||||||
now = datetime.datetime.now(datetime.timezone.utc)
|
now = datetime.datetime.now(datetime.timezone.utc)
|
||||||
if now > self._next_iteration:
|
if now > self._next_iteration:
|
||||||
self._next_iteration = now
|
self._next_iteration = now
|
||||||
except self._valid_exception as exc:
|
except self._valid_exception as exc:
|
||||||
|
self._last_iteration_failed = True
|
||||||
if not self.reconnect:
|
if not self.reconnect:
|
||||||
raise
|
raise
|
||||||
await asyncio.sleep(backoff.delay())
|
await asyncio.sleep(backoff.delay())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user