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

The `http_client` is instantiated with the agent, and reused all the
time. If the connection fails and closes, it's sometimes not possible
to reuse it.# Please enter the commit message for your changes. Lines
starting

Fixes #37
This commit is contained in:
Alexis Métaireau 2024-04-16 10:09:02 +02:00
parent 69cf92c83b
commit dbf11ef3db
No known key found for this signature in database
GPG key ID: 1C21B876828E5FF2

View file

@ -39,15 +39,15 @@ 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 = {
"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":