Skip to content

Commit 20e66ba

Browse files
author
Andrei Neagu
committed
addeddelay
1 parent 649cd38 commit 20e66ba

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/service-library/src/servicelib/deferred_tasks/_base_deferred_handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ async def get_retries(cls, context: DeferredContext) -> NonNegativeInt:
4646
return 0
4747

4848
@classmethod
49-
async def get_retry_delay(cls, context: DeferredContext) -> timedelta:
49+
async def get_retry_delay(
50+
cls, context: DeferredContext, remaining_attempts: NonNegativeInt
51+
) -> timedelta:
5052
"""
5153
returns: the delay between eatch retry attempt (default: 0s)
5254
"""
5355
assert context # nosec
56+
assert remaining_attempts # nosec
5457
return timedelta(seconds=0)
5558

5659
@classmethod

packages/service-library/src/servicelib/deferred_tasks/_deferred_manager.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,15 @@ async def _fs_handle_error_result( # pylint:disable=method-hidden
460460
task_schedule.result, TaskResultCancelledError
461461
):
462462
_logger.debug("Schedule retry attempt for task_uid '%s'", task_uid)
463-
# does not retry if task was cancelled
463+
464+
subclass = self.__get_subclass(task_schedule.class_unique_reference)
465+
deferred_context = self.__get_deferred_context(task_schedule.start_context)
466+
sleep_interval = await subclass.get_retry_delay(
467+
context=deferred_context,
468+
remaining_attempts=task_schedule.execution_attempts,
469+
)
470+
await asyncio.sleep(sleep_interval.total_seconds())
471+
464472
task_schedule.state = TaskState.SUBMIT_TASK
465473
await self._task_tracker.save(task_uid, task_schedule)
466474
await self.__publish_to_queue(task_uid, _FastStreamRabbitQueue.SUBMIT_TASK)

0 commit comments

Comments
 (0)