diff --git a/arangoasync/aql.py b/arangoasync/aql.py index b81cade..1fad880 100644 --- a/arangoasync/aql.py +++ b/arangoasync/aql.py @@ -16,6 +16,7 @@ AQLQueryClearError, AQLQueryExecuteError, AQLQueryExplainError, + AQLQueryHistoryError, AQLQueryKillError, AQLQueryListError, AQLQueryRulesGetError, @@ -426,6 +427,25 @@ def response_handler(resp: Response) -> QueryTrackingConfiguration: return await self._executor.execute(request, response_handler) + async def history(self) -> Result[Json]: + """Return recently executed AQL queries (admin only). + + Returns: + dict: AQL query history. + + Raises: + AQLQueryHistoryError: If retrieval fails. + """ + request = Request(method=Method.GET, endpoint="/_admin/server/aql-queries") + + def response_handler(resp: Response) -> Json: + if not resp.is_success: + raise AQLQueryHistoryError(resp, request) + result: Json = self.deserializer.loads(resp.raw_body) + return cast(Json, result["result"]) + + return await self._executor.execute(request, response_handler) + async def queries(self, all_queries: bool = False) -> Result[Jsons]: """Return a list of currently running queries. diff --git a/arangoasync/exceptions.py b/arangoasync/exceptions.py index 5a904ee..a940e1b 100644 --- a/arangoasync/exceptions.py +++ b/arangoasync/exceptions.py @@ -111,6 +111,10 @@ class AQLQueryExplainError(ArangoServerError): """Failed to parse and explain query.""" +class AQLQueryHistoryError(ArangoServerError): + """Failed to retrieve running AQL queries.""" + + class AQLQueryKillError(ArangoServerError): """Failed to kill the query.""" diff --git a/arangoasync/version.py b/arangoasync/version.py index 7863915..976498a 100644 --- a/arangoasync/version.py +++ b/arangoasync/version.py @@ -1 +1 @@ -__version__ = "1.0.2" +__version__ = "1.0.3" diff --git a/tests/test_aql.py b/tests/test_aql.py index ab5ba19..24f233f 100644 --- a/tests/test_aql.py +++ b/tests/test_aql.py @@ -21,6 +21,7 @@ AQLQueryClearError, AQLQueryExecuteError, AQLQueryExplainError, + AQLQueryHistoryError, AQLQueryKillError, AQLQueryListError, AQLQueryRulesGetError, @@ -96,6 +97,8 @@ async def test_list_queries(superuser, db, bad_db): _ = await superuser.aql.slow_queries(all_queries=True) await aql.clear_slow_queries() await superuser.aql.clear_slow_queries(all_queries=True) + history = await superuser.aql.history() + assert isinstance(history, dict) with pytest.raises(AQLQueryListError): _ = await bad_db.aql.queries() @@ -109,6 +112,8 @@ async def test_list_queries(superuser, db, bad_db): _ = await aql.slow_queries(all_queries=True) with pytest.raises(AQLQueryClearError): await aql.clear_slow_queries(all_queries=True) + with pytest.raises(AQLQueryHistoryError): + _ = await bad_db.aql.history() long_running_task.cancel()