Skip to content

Commit a234cf0

Browse files
committed
retry using tenacity
1 parent 9c1af75 commit a234cf0

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

servicex/servicex_adapter.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
from typing import Optional, Dict, List
3131

3232
import httpx
33-
from aiohttp_retry import RetryClient, ExponentialRetry, asyncio
33+
from aiohttp_retry import RetryClient, ExponentialRetry
3434
from google.auth import jwt
35+
from tenacity import AsyncRetrying, stop_after_attempt, wait_fixed
3536

3637
from servicex.models import TransformRequest, TransformStatus
3738

@@ -133,20 +134,21 @@ async def get_transform_status(self, request_id: str) -> TransformStatus:
133134
headers = await self._get_authorization()
134135
retry_options = ExponentialRetry(attempts=5, start_timeout=10)
135136
async with RetryClient(retry_options=retry_options) as client:
136-
retries = 5
137-
for retry in range(retries):
138-
try:
139-
async with client.get(url=f"{self.url}/servicex/transformation/{request_id}",
140-
headers=headers) as r:
141-
if r.status == 401:
142-
raise AuthorizationError("Not authorized to access serviceX"
143-
f"at {self.url}")
144-
if r.status == 404:
145-
raise ValueError(f"Transform ID {request_id} not found")
146-
o = await r.json()
147-
return TransformStatus(**o)
148-
except RuntimeError as e:
149-
if retry == retries:
150-
raise RuntimeError("ServiceX WebAPI Error"
151-
f"while getting transform status: {e}")
152-
await asyncio.sleep(3)
137+
try:
138+
async for attempt in AsyncRetrying(stop=stop_after_attempt(5),
139+
wait=wait_fixed(3),
140+
reraise=True):
141+
with attempt:
142+
async with client.get(url=f"{self.url}/servicex/"
143+
f"transformation/{request_id}",
144+
headers=headers) as r:
145+
if r.status == 401:
146+
raise AuthorizationError("Not authorized to access serviceX"
147+
f"at {self.url}")
148+
if r.status == 404:
149+
raise ValueError(f"Transform ID {request_id} not found")
150+
o = await r.json()
151+
return TransformStatus(**o)
152+
except RuntimeError as e:
153+
raise RuntimeError("ServiceX WebAPI Error "
154+
f"while getting transform status: {e}")

0 commit comments

Comments
 (0)