Skip to content

Commit c768d34

Browse files
committed
Format code
1 parent 07a818a commit c768d34

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
* Reduce calls to the Aura API during GdsSessions::get_or_create.
1616
* Improve error message when a query is interrupted by a signal (SIGINT or SIGTERM).
17+
* Improve error message if session is expired.
1718

1819

1920
## Other changes

graphdatascience/session/aura_api.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,16 @@ def wait_for_session_running(
173173
session = self.get_session(session_id)
174174
if session is None:
175175
return WaitResult.from_error(f"Session `{session_id}` not found -- please retry")
176-
elif session.status == "Ready" and session.host: # check host needed until dns based routing
176+
elif session.status == "Ready":
177177
return WaitResult.from_connection_url(session.bolt_connection_url())
178178
elif session.status == "Failed":
179-
return WaitResult.from_error(f"Session `{session_id}` failed due to: {session.errors}")
179+
return WaitResult.from_error(
180+
f"Session `{session_id}` with name `{session.name}` failed due to: {session.errors}"
181+
)
182+
elif session.is_expired():
183+
return WaitResult.from_error(
184+
f"Session `{session_id}` with name `{session.name}` is expired. Expired due to: {session.errors}"
185+
)
180186
else:
181187
self._logger.debug(
182188
f"Session `{session_id}` is not yet running. "

graphdatascience/tests/unit/test_aura_api.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,35 @@ def test_wait_for_session_running_until_failure(requests_mock: Mocker) -> None:
676676
api = AuraApi("", "", tenant_id="some-tenant")
677677

678678
assert api.wait_for_session_running("id0") == WaitResult.from_error(
679-
"Session `id0` failed due to: [SessionError(message='Session reached its memory limit. Create a larger instance.', reason='OutOfMemory')]"
679+
"Session `id0` with name `name-0` failed due to: [SessionError(message='Session reached its memory limit. Create a larger instance.', reason='OutOfMemory')]"
680+
)
681+
682+
683+
def test_wait_for_session_running_until_expired(requests_mock: Mocker) -> None:
684+
mock_auth_token(requests_mock)
685+
requests_mock.get(
686+
"https://api.neo4j.io/v1beta5/data-science/sessions/id0",
687+
json={
688+
"data": {
689+
"id": "id0",
690+
"name": "name-0",
691+
"status": "Expired",
692+
"instance_id": "dbid-1",
693+
"created_at": "1970-01-01T00:00:00Z",
694+
"host": "foo.bar",
695+
"memory": "4Gi",
696+
"expiry_date": "1977-01-01T00:00:00Z",
697+
"tenant_id": "tenant-1",
698+
"user_id": "user-1",
699+
},
700+
"errors": [{"id": "id0", "message": "Session is expired", "reason": "Due to Inactivity"}],
701+
},
702+
)
703+
704+
api = AuraApi("", "", tenant_id="some-tenant")
705+
706+
assert api.wait_for_session_running("id0") == WaitResult.from_error(
707+
"Session `id0` with name `name-0` is expired. Expired due to: [SessionError(message='Session is expired', reason='Due to Inactivity')]"
680708
)
681709

682710

0 commit comments

Comments
 (0)