Create a new http client on agent retry

This commit is contained in:
Alexis Métaireau 2023-10-20 01:35:30 +02:00
parent 93fb9cebca
commit 158e7ac44c
2 changed files with 5 additions and 5 deletions

View file

@ -4,7 +4,6 @@ Argos is an HTTP monitoring service. It allows you to define a list of websites
Todo:
- [ ] Retrying: attempt 1413 ended with: <Future at 0x104f39390 state=finished raised RuntimeError> Cannot reopen a client instance, once it has been closed.
- [ ] Cleandb should keep max number of results by task
- [ ] Do not return empty list on / when no results from agents.
- [ ] Last seen agents

View file

@ -32,16 +32,17 @@ class ArgosAgent:
self.server = server
self.max_tasks = max_tasks
self.wait_time = wait_time
self.auth = auth
self.agent_id = socket.gethostname()
headers = {
"Authorization": f"Bearer {auth}",
}
self._http_client = httpx.AsyncClient(headers=headers)
@retry(after=log_failure, wait=wait_random(min=1, max=2))
async def run(self):
logger.info(f"Running agent against {self.server}")
headers = {
"Authorization": f"Bearer {self.auth}",
}
self._http_client = httpx.AsyncClient(headers=headers)
async with self._http_client:
while True:
retry_now = await self._get_and_complete_tasks()