|
| 1 | +from typing import Awaitable, Callable, Optional, TypeVar |
| 2 | + |
| 3 | +from hyperbrowser.models.consts import POLLING_ATTEMPTS |
| 4 | + |
| 5 | +from ..polling import ( |
| 6 | + collect_paginated_results, |
| 7 | + collect_paginated_results_async, |
| 8 | + retry_operation, |
| 9 | + retry_operation_async, |
| 10 | +) |
| 11 | + |
| 12 | +T = TypeVar("T") |
| 13 | +R = TypeVar("R") |
| 14 | + |
| 15 | + |
| 16 | +def retry_operation_with_defaults( |
| 17 | + *, |
| 18 | + operation_name: str, |
| 19 | + operation: Callable[[], T], |
| 20 | +) -> T: |
| 21 | + return retry_operation( |
| 22 | + operation_name=operation_name, |
| 23 | + operation=operation, |
| 24 | + max_attempts=POLLING_ATTEMPTS, |
| 25 | + retry_delay_seconds=0.5, |
| 26 | + ) |
| 27 | + |
| 28 | + |
| 29 | +async def retry_operation_with_defaults_async( |
| 30 | + *, |
| 31 | + operation_name: str, |
| 32 | + operation: Callable[[], Awaitable[T]], |
| 33 | +) -> T: |
| 34 | + return await retry_operation_async( |
| 35 | + operation_name=operation_name, |
| 36 | + operation=operation, |
| 37 | + max_attempts=POLLING_ATTEMPTS, |
| 38 | + retry_delay_seconds=0.5, |
| 39 | + ) |
| 40 | + |
| 41 | + |
| 42 | +def collect_paginated_results_with_defaults( |
| 43 | + *, |
| 44 | + operation_name: str, |
| 45 | + get_next_page: Callable[[int], R], |
| 46 | + get_current_page_batch: Callable[[R], int], |
| 47 | + get_total_page_batches: Callable[[R], int], |
| 48 | + on_page_success: Callable[[R], None], |
| 49 | + max_wait_seconds: Optional[float], |
| 50 | +) -> None: |
| 51 | + collect_paginated_results( |
| 52 | + operation_name=operation_name, |
| 53 | + get_next_page=get_next_page, |
| 54 | + get_current_page_batch=get_current_page_batch, |
| 55 | + get_total_page_batches=get_total_page_batches, |
| 56 | + on_page_success=on_page_success, |
| 57 | + max_wait_seconds=max_wait_seconds, |
| 58 | + max_attempts=POLLING_ATTEMPTS, |
| 59 | + retry_delay_seconds=0.5, |
| 60 | + ) |
| 61 | + |
| 62 | + |
| 63 | +async def collect_paginated_results_with_defaults_async( |
| 64 | + *, |
| 65 | + operation_name: str, |
| 66 | + get_next_page: Callable[[int], Awaitable[R]], |
| 67 | + get_current_page_batch: Callable[[R], int], |
| 68 | + get_total_page_batches: Callable[[R], int], |
| 69 | + on_page_success: Callable[[R], None], |
| 70 | + max_wait_seconds: Optional[float], |
| 71 | +) -> None: |
| 72 | + await collect_paginated_results_async( |
| 73 | + operation_name=operation_name, |
| 74 | + get_next_page=get_next_page, |
| 75 | + get_current_page_batch=get_current_page_batch, |
| 76 | + get_total_page_batches=get_total_page_batches, |
| 77 | + on_page_success=on_page_success, |
| 78 | + max_wait_seconds=max_wait_seconds, |
| 79 | + max_attempts=POLLING_ATTEMPTS, |
| 80 | + retry_delay_seconds=0.5, |
| 81 | + ) |
0 commit comments