Compare commits

...

2 Commits

Author SHA1 Message Date
Boris Tasevski
2303c40992 Added support for additional python decorator timed_read_proc 2021-10-19 13:57:23 +02:00
Antonio Andelic
a647eb7926 Bump version to 2.0.1 2021-10-13 10:10:43 +02:00
2 changed files with 24 additions and 7 deletions

View File

@@ -54,7 +54,7 @@ option(MG_ENTERPRISE "Build Memgraph Enterprise Edition" ON)
# Set the current version here to override the automatic version detection. The
# version must be specified as `X.Y.Z`. Primarily used when building new patch
# versions.
set(MEMGRAPH_OVERRIDE_VERSION "")
set(MEMGRAPH_OVERRIDE_VERSION "2.0.1")
# Custom suffix that this version should have. The suffix can be any arbitrary
# string. Primarily used when building a version for a specific customer.

View File

@@ -1118,7 +1118,7 @@ def raise_if_does_not_meet_requirements(func: typing.Callable[..., Record]):
def _register_proc(func: typing.Callable[..., Record],
is_write: bool):
is_write: bool, is_timed: bool):
raise_if_does_not_meet_requirements(func)
register_func = (
_mgp.Module.add_write_procedure if is_write
@@ -1128,13 +1128,23 @@ def _register_proc(func: typing.Callable[..., Record],
if params and params[0].annotation is ProcCtx:
@wraps(func)
def wrapper(graph, args):
return func(ProcCtx(graph), *args)
start = datetime.datetime.now()
result = func(ProcCtx(graph), *args)
if is_timed:
delta = datetime.datetime.now() - start
result.fields["duration"] = delta.total_seconds() * 10**6 + delta.microseconds % 10**6
return result
params = params[1:]
mgp_proc = register_func(_mgp._MODULE, wrapper)
else:
@wraps(func)
def wrapper(graph, args):
return func(*args)
start = datetime.datetime.now()
result = func(*args)
if is_timed:
delta = datetime.datetime.now() - start
result.fields["duration"] = delta.total_seconds() * 10**6 + delta.microseconds % 10**6
return result
mgp_proc = register_func(_mgp._MODULE, wrapper)
for param in params:
name = param.name
@@ -1157,10 +1167,17 @@ def _register_proc(func: typing.Callable[..., Record],
mgp_proc.add_deprecated_result(name, cypher_type)
else:
mgp_proc.add_result(name, _typing_to_cypher_type(type_))
if is_timed:
mgp_proc.add_result("duration", _typing_to_cypher_type(int))
return func
def read_proc(func: typing.Callable[..., Record]):
_read_proc(func, False)
def timed_read_proc(func: typing.Callable[..., Record]):
_read_proc(func, True)
def _read_proc(func: typing.Callable[..., Record], is_timed: bool):
"""
Register `func` as a read-only procedure of the current module.
@@ -1200,7 +1217,7 @@ def read_proc(func: typing.Callable[..., Record]):
CALL example.procedure(1) YIELD args, result;
Naturally, you may pass in different arguments or yield less fields.
"""
return _register_proc(func, False)
return _register_proc(func, False, is_timed)
def write_proc(func: typing.Callable[..., Record]):
@@ -1250,7 +1267,7 @@ def write_proc(func: typing.Callable[..., Record]):
CALL example.procedure("single argument") YIELD result;
Naturally, you may pass in different arguments.
"""
return _register_proc(func, True)
return _register_proc(func, True, False)
class InvalidMessageError(Exception):