🔀 Merge branch 'fix/reinit-http-client-on-failures' into 'main'

fix(agent): Do not reuse `http_client` on failures.

Closes #37

See merge request framasoft/framaspace/argos!46
This commit is contained in:
Luc Didry 2024-04-25 10:08:29 +00:00
commit 02a4d5c30b

View file

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