Expose query timeout checking to modules
Summary: - Add the `mgp_must_abort(const mgp_graph *graph)` C API. - Add the `ProcCtx.must_abort()` Python API. The usage is very simple -- the function returns a boolean indicating whether the procedure should abort. Reviewers: mferencevic, dsantl Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2742
This commit is contained in:
@@ -531,6 +531,11 @@ class Graph:
|
||||
return Vertices(self._graph)
|
||||
|
||||
|
||||
class AbortError(Exception):
|
||||
'''Signals that the procedure was asked to abort its execution.'''
|
||||
pass
|
||||
|
||||
|
||||
class ProcCtx:
|
||||
'''Context of a procedure being executed.
|
||||
|
||||
@@ -554,6 +559,15 @@ class ProcCtx:
|
||||
raise InvalidContextError()
|
||||
return self._graph
|
||||
|
||||
def must_abort(self) -> bool:
|
||||
if not self.is_valid():
|
||||
raise InvalidContextError()
|
||||
return self._graph._graph.must_abort()
|
||||
|
||||
def check_must_abort(self):
|
||||
if self.must_abort():
|
||||
raise AbortError
|
||||
|
||||
|
||||
# Additional typing support
|
||||
|
||||
|
||||
Reference in New Issue
Block a user