Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner committed Jan 8, 2025
1 parent 2940de9 commit f1859fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions aio_request/deadline_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DeadlineProvider = Callable[[Deadline, int, int], Deadline]


def split_deadline_between_attempts(*, split_factor: int | None = None) -> DeadlineProvider:
def split_deadline_between_attempts(*, attempts_count_to_split: int | None = None) -> DeadlineProvider:
"""
Split deadline between attempts.
Expand All @@ -18,19 +18,19 @@ def split_deadline_between_attempts(*, split_factor: int | None = None) -> Deadl
the last one has received the remaining 8 seconds due to redistribution.
"""

if split_factor is not None and split_factor < 2:
raise ValueError("split_factor should be greater or equal to 2")
if attempts_count_to_split is not None and attempts_count_to_split < 2:
raise ValueError("attempts_count_to_split should be greater or equal to 2")

def __provider(deadline: Deadline, attempt: int, attempts_count: int) -> Deadline:
if deadline.expired:
return deadline
if split_factor is None:
effective_split_factor = attempts_count - attempt
if attempts_count_to_split is None:
effective_attempts_left = attempts_count - attempt
else:
effective_split_factor = min(split_factor, attempts_count) - attempt
if effective_split_factor <= 1:
effective_attempts_left = min(attempts_count_to_split, attempts_count) - attempt
if effective_attempts_left <= 1:
return deadline
return deadline / effective_split_factor
return deadline / effective_attempts_left

return __provider

Expand Down
4 changes: 2 additions & 2 deletions tests/test_deadline_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def test_split_deadline_between_attempt():


async def test_split_deadline_between_attempt_with_split_factor():
provider = aio_request.split_deadline_between_attempts(split_factor=2)
provider = aio_request.split_deadline_between_attempts(attempts_count_to_split=2)
deadline = aio_request.Deadline.from_timeout(1)

attempt_deadline = provider(deadline, 0, 3)
Expand Down Expand Up @@ -56,7 +56,7 @@ async def test_split_deadline_between_attempts_fast_attempt_failure():


async def test_split_deadline_between_attempts_fast_attempt_failure_with_split_factor():
provider = aio_request.split_deadline_between_attempts(split_factor=2)
provider = aio_request.split_deadline_between_attempts(attempts_count_to_split=2)
deadline = aio_request.Deadline.from_timeout(1)

attempt_deadline = provider(deadline, 0, 3)
Expand Down

0 comments on commit f1859fe

Please sign in to comment.