11import asyncio
22import logging
33from collections .abc import AsyncGenerator
4- from typing import Any
4+ from datetime import timedelta
5+ from typing import Any , Final
56
67from aiohttp import ClientConnectionError , ClientSession
8+ from pydantic import PositiveFloat
79from tenacity import TryAgain , retry
810from tenacity .asyncio import AsyncRetrying
911from tenacity .before_sleep import before_sleep_log
1214from tenacity .wait import wait_random_exponential
1315from yarl import URL
1416
15- from ...long_running_tasks .constants import DEFAULT_POLL_INTERVAL_S , HOUR
17+ from ...long_running_tasks .constants import DEFAULT_POLL_INTERVAL_S
1618from ...long_running_tasks .models import (
1719 LRTask ,
1820 RequestBody ,
2628
2729_logger = logging .getLogger (__name__ )
2830
31+ _DEFAULT_CLIENT_TIMEOUT_S : Final [PositiveFloat ] = timedelta (hours = 1 ).total_seconds ()
2932
3033_DEFAULT_AIOHTTP_RETRY_POLICY : dict [str , Any ] = {
3134 "retry" : retry_if_exception_type (ClientConnectionError ),
@@ -49,7 +52,7 @@ async def _wait_for_completion(
4952 session : ClientSession ,
5053 task_id : TaskId ,
5154 status_url : URL ,
52- client_timeout : int ,
55+ client_timeout : PositiveFloat ,
5356) -> AsyncGenerator [TaskProgress , None ]:
5457 try :
5558 async for attempt in AsyncRetrying (
@@ -98,7 +101,7 @@ async def long_running_task_request(
98101 session : ClientSession ,
99102 url : URL ,
100103 json : RequestBody | None = None ,
101- client_timeout : int = 1 * HOUR ,
104+ client_timeout : PositiveFloat = _DEFAULT_CLIENT_TIMEOUT_S ,
102105) -> AsyncGenerator [LRTask , None ]:
103106 """Will use the passed `ClientSession` to call an oSparc long
104107 running task `url` passing `json` as request body.
0 commit comments