mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
🐛 — Better httpx.RequestError handling (fix #83)
This commit is contained in:
parent
23fea9fffa
commit
c3708af32a
2 changed files with 15 additions and 3 deletions
|
@ -8,6 +8,7 @@
|
||||||
- ✨ — No need cron tasks for agents watching (#76)
|
- ✨ — No need cron tasks for agents watching (#76)
|
||||||
- ✨ — Reload configuration asynchronously (#79)
|
- ✨ — Reload configuration asynchronously (#79)
|
||||||
- 🐛 — Automatically reconnect to LDAP if unreachable (#81)
|
- 🐛 — Automatically reconnect to LDAP if unreachable (#81)
|
||||||
|
- 🐛 — Better httpx.RequestError handling (#83)
|
||||||
|
|
||||||
## 0.7.4
|
## 0.7.4
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes
|
||||||
await asyncio.sleep(self.wait_time)
|
await asyncio.sleep(self.wait_time)
|
||||||
|
|
||||||
async def _do_request(self, group: str, details: dict):
|
async def _do_request(self, group: str, details: dict):
|
||||||
|
logger.debug("_do_request for group %s", group)
|
||||||
headers = {}
|
headers = {}
|
||||||
if details["request_data"] is not None:
|
if details["request_data"] is not None:
|
||||||
request_data = json.loads(details["request_data"])
|
request_data = json.loads(details["request_data"])
|
||||||
|
@ -120,6 +121,7 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes
|
||||||
)
|
)
|
||||||
except httpx.ReadError:
|
except httpx.ReadError:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
logger.warning("httpx.ReadError for group %s, re-emit request", group)
|
||||||
if details["request_data"] is None or request_data["data"] is None:
|
if details["request_data"] is None or request_data["data"] is None:
|
||||||
response = await http_client.request( # type: ignore[union-attr]
|
response = await http_client.request( # type: ignore[union-attr]
|
||||||
method=details["method"], url=details["url"], timeout=60
|
method=details["method"], url=details["url"], timeout=60
|
||||||
|
@ -138,6 +140,9 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes
|
||||||
data=request_data["data"],
|
data=request_data["data"],
|
||||||
timeout=60,
|
timeout=60,
|
||||||
)
|
)
|
||||||
|
except httpx.RequestError as err:
|
||||||
|
logger.warning("httpx.RequestError for group %s", group)
|
||||||
|
response = err
|
||||||
|
|
||||||
self._res_cache[group] = response
|
self._res_cache[group] = response
|
||||||
|
|
||||||
|
@ -147,15 +152,21 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes
|
||||||
|
|
||||||
check_class = get_registered_check(task.check)
|
check_class = get_registered_check(task.check)
|
||||||
check = check_class(task)
|
check = check_class(task)
|
||||||
result = await check.run(self._res_cache[task.task_group])
|
|
||||||
|
response = self._res_cache[task.task_group]
|
||||||
|
if isinstance(response, httpx.Response):
|
||||||
|
result = await check.run(response)
|
||||||
status = result.status
|
status = result.status
|
||||||
context = result.context
|
context = result.context
|
||||||
|
else:
|
||||||
|
status = "failure"
|
||||||
|
context = SerializableException.from_exception(response)
|
||||||
except Exception as err: # pylint: disable=broad-except
|
except Exception as err: # pylint: disable=broad-except
|
||||||
status = "error"
|
status = "error"
|
||||||
context = SerializableException.from_exception(err)
|
context = SerializableException.from_exception(err)
|
||||||
msg = f"An exception occured when running {_task}. {err.__class__.__name__} : {err}"
|
msg = f"An exception occured when running {_task}. {err.__class__.__name__} : {err}"
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
|
|
||||||
return AgentResult(task_id=task.id, status=status, context=context)
|
return AgentResult(task_id=task.id, status=status, context=context)
|
||||||
|
|
||||||
async def _get_and_complete_tasks(self):
|
async def _get_and_complete_tasks(self):
|
||||||
|
|
Loading…
Reference in a new issue