Skip to content

Commit 414a4de

Browse files
authored
/_admin/server/aql-queries (#71)
* Implemented /_admin/server/api-calls * Version bump
1 parent b4e4bb5 commit 414a4de

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

arangoasync/aql.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
AQLQueryClearError,
1717
AQLQueryExecuteError,
1818
AQLQueryExplainError,
19+
AQLQueryHistoryError,
1920
AQLQueryKillError,
2021
AQLQueryListError,
2122
AQLQueryRulesGetError,
@@ -426,6 +427,25 @@ def response_handler(resp: Response) -> QueryTrackingConfiguration:
426427

427428
return await self._executor.execute(request, response_handler)
428429

430+
async def history(self) -> Result[Json]:
431+
"""Return recently executed AQL queries (admin only).
432+
433+
Returns:
434+
dict: AQL query history.
435+
436+
Raises:
437+
AQLQueryHistoryError: If retrieval fails.
438+
"""
439+
request = Request(method=Method.GET, endpoint="/_admin/server/aql-queries")
440+
441+
def response_handler(resp: Response) -> Json:
442+
if not resp.is_success:
443+
raise AQLQueryHistoryError(resp, request)
444+
result: Json = self.deserializer.loads(resp.raw_body)
445+
return cast(Json, result["result"])
446+
447+
return await self._executor.execute(request, response_handler)
448+
429449
async def queries(self, all_queries: bool = False) -> Result[Jsons]:
430450
"""Return a list of currently running queries.
431451

arangoasync/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class AQLQueryExplainError(ArangoServerError):
111111
"""Failed to parse and explain query."""
112112

113113

114+
class AQLQueryHistoryError(ArangoServerError):
115+
"""Failed to retrieve running AQL queries."""
116+
117+
114118
class AQLQueryKillError(ArangoServerError):
115119
"""Failed to kill the query."""
116120

arangoasync/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.2"
1+
__version__ = "1.0.3"

tests/test_aql.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
AQLQueryClearError,
2222
AQLQueryExecuteError,
2323
AQLQueryExplainError,
24+
AQLQueryHistoryError,
2425
AQLQueryKillError,
2526
AQLQueryListError,
2627
AQLQueryRulesGetError,
@@ -96,6 +97,8 @@ async def test_list_queries(superuser, db, bad_db):
9697
_ = await superuser.aql.slow_queries(all_queries=True)
9798
await aql.clear_slow_queries()
9899
await superuser.aql.clear_slow_queries(all_queries=True)
100+
history = await superuser.aql.history()
101+
assert isinstance(history, dict)
99102

100103
with pytest.raises(AQLQueryListError):
101104
_ = await bad_db.aql.queries()
@@ -109,6 +112,8 @@ async def test_list_queries(superuser, db, bad_db):
109112
_ = await aql.slow_queries(all_queries=True)
110113
with pytest.raises(AQLQueryClearError):
111114
await aql.clear_slow_queries(all_queries=True)
115+
with pytest.raises(AQLQueryHistoryError):
116+
_ = await bad_db.aql.history()
112117

113118
long_running_task.cancel()
114119

0 commit comments

Comments
 (0)