Skip to content

Commit

Permalink
wait on a 429 response
Browse files Browse the repository at this point in the history
  • Loading branch information
denniswittich committed Feb 28, 2025
1 parent 47552d1 commit f506994
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion learning_loop_node/detector/outbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def _upload_batch(self, items: List[str]):

try:
async with aiohttp.ClientSession() as session:
response = await session.post(self.target_uri, data=data, timeout=self.UPLOAD_TIMEOUT_S)
response = await session.post(self.target_uri, data=data, timeout=aiohttp.ClientTimeout(total=self.UPLOAD_TIMEOUT_S))
except Exception:
self.log.exception('Could not upload images')
return
Expand Down Expand Up @@ -176,6 +176,9 @@ async def _upload_batch(self, items: List[str]):
self.log.exception('Broken content in batch. Splitting and retrying')
await self._upload_batch(items[:len(items)//2])
await self._upload_batch(items[len(items)//2:])
elif response.status == 429:
self.log.error('Too many requests: %s', response.content)
await asyncio.sleep(5)
else:
self.log.error('Could not upload images: %s', response.content)

Expand Down

0 comments on commit f506994

Please sign in to comment.