Skip to content

Commit

Permalink
fix(interactive): Fix list_jobs API (#4286)
Browse files Browse the repository at this point in the history
Fix the problem in `list_jobs` API #4247
  • Loading branch information
zhanglei1949 authored Oct 12, 2024
1 parent 5d89a61 commit 7734584
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
6 changes: 2 additions & 4 deletions flex/engines/http_server/actor/admin_actor.act.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,15 @@ gs::Result<seastar::sstring> to_json_str(
const std::vector<gs::JobMeta>& job_metas) {
rapidjson::Document res(rapidjson::kArrayType);
for (auto& job_meta : job_metas) {
rapidjson::Document job_json;
rapidjson::Document job_json(rapidjson::kObjectType, &res.GetAllocator());
if (job_json.Parse(job_meta.ToJson().c_str()).HasParseError()) {
LOG(ERROR) << "Fail to parse job meta";
return gs::Result<seastar::sstring>(gs::Status(
gs::StatusCode::INTERNAL_ERROR, "Fail to parse job meta: "));
}
res.PushBack(job_json, res.GetAllocator());
}
return res.Empty()
? gs::Result<seastar::sstring>("{}")
: gs::Result<seastar::sstring>(gs::rapidjson_stringify(res));
return gs::Result<seastar::sstring>(gs::rapidjson_stringify(res));
}

admin_actor::~admin_actor() {
Expand Down
3 changes: 3 additions & 0 deletions flex/interactive/sdk/python/gs_interactive/client/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from gs_interactive.exceptions import ForbiddenException
from gs_interactive.exceptions import NotFoundException
from gs_interactive.exceptions import ServiceException
from urllib3.exceptions import MaxRetryError

from gs_interactive.client.generated.interactive_pb2 import Code as StatusCode
from gs_interactive.models.api_response_with_code import APIResponseWithCode
Expand Down Expand Up @@ -105,6 +106,8 @@ def from_exception(exception: ApiException):
return Status(StatusCode.SERVICE_UNAVAILABLE, exception.body)
else:
return Status(StatusCode.INTERNAL_ERROR, exception.body)
elif isinstance(exception, MaxRetryError):
return Status(StatusCode.INTERNAL_ERROR, exception)
return Status(
StatusCode.UNKNOWN, "Unknown Error from exception " + exception.body
)
Expand Down
15 changes: 11 additions & 4 deletions flex/interactive/sdk/python/gs_interactive/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def neo4j_session(interactive_driver):
_neo4j_sess.close()


@pytest.fixture(scope="module")
@pytest.fixture(scope="function")
def create_modern_graph(interactive_session):
create_graph_request = CreateGraphRequest.from_dict(modern_graph_full)
resp = interactive_session.create_graph(create_graph_request)
Expand All @@ -314,7 +314,7 @@ def create_modern_graph(interactive_session):
delete_running_graph(interactive_session, graph_id)


@pytest.fixture(scope="module")
@pytest.fixture(scope="function")
def create_vertex_only_modern_graph(interactive_session):
create_graph_request = CreateGraphRequest.from_dict(modern_graph_vertex_only)
resp = interactive_session.create_graph(create_graph_request)
Expand All @@ -324,7 +324,7 @@ def create_vertex_only_modern_graph(interactive_session):
delete_running_graph(interactive_session, graph_id)


@pytest.fixture(scope="module")
@pytest.fixture(scope="function")
def create_partial_modern_graph(interactive_session):
create_graph_request = CreateGraphRequest.from_dict(modern_graph_partial)
resp = interactive_session.create_graph(create_graph_request)
Expand Down Expand Up @@ -357,6 +357,14 @@ def import_data_to_vertex_only_modern_graph(sess: Session, graph_id: str):
assert wait_job_finish(sess, job_id)


def import_data_to_vertex_only_modern_graph_no_wait(sess: Session, graph_id: str):
schema_mapping = SchemaMapping.from_dict(modern_graph_vertex_only_import_config)
resp = sess.bulk_loading(graph_id, schema_mapping)
assert resp.is_ok()
job_id = resp.get_value().job_id
print("job_id: ", job_id)


def import_data_to_partial_modern_graph(sess: Session, graph_id: str):
schema_mapping = SchemaMapping.from_dict(modern_graph_partial_import_config)
resp = sess.bulk_loading(graph_id, schema_mapping)
Expand Down Expand Up @@ -414,7 +422,6 @@ def delete_running_graph(sess: Session, graph_id: str):
assert resp.is_ok()
# drop the graph
resp = sess.delete_graph(graph_id)
assert resp.is_ok()


def create_procedure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
from gs_interactive.tests.conftest import import_data_to_full_modern_graph
from gs_interactive.tests.conftest import import_data_to_partial_modern_graph
from gs_interactive.tests.conftest import import_data_to_vertex_only_modern_graph
from gs_interactive.tests.conftest import (
import_data_to_vertex_only_modern_graph_no_wait,
)
from gs_interactive.tests.conftest import run_cypher_test_suite
from gs_interactive.tests.conftest import start_service_on_graph
from gs_interactive.tests.conftest import update_procedure
Expand Down Expand Up @@ -236,3 +239,14 @@ def test_builtin_procedure(interactive_session, neo4j_session, create_modern_gra
'"person"',
"4L",
)


def test_list_jobs(interactive_session, create_vertex_only_modern_graph):
print("[Test list jobs]")
import_data_to_vertex_only_modern_graph_no_wait(
interactive_session, create_vertex_only_modern_graph
)
resp = interactive_session.delete_graph(create_vertex_only_modern_graph)

resp = interactive_session.list_jobs()
assert resp.is_ok() and len(resp.get_value()) > 0
3 changes: 2 additions & 1 deletion flex/interactive/sdk/python/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[isort]
profile = black
ensure_newline_before_comments = True
line_length = 88
force_single_line = True
Expand Down Expand Up @@ -28,4 +29,4 @@ extend-exclude =
gs_interactive/rest.py

[pylint]
max-line-length = 88
max-line-length = 88

0 comments on commit 7734584

Please sign in to comment.