Skip to content

Commit

Permalink
feat: add rpc method to close sessions (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
aneojgurhem authored Feb 16, 2024
2 parents 46ef2b9 + d23a5f8 commit 8d52f10
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Protos/V1/session_status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum SessionStatus {
SESSION_STATUS_RUNNING = 1; /** Session is open and accepting tasks for execution. */
SESSION_STATUS_CANCELLED = 2; /** Session is cancelled. No more tasks can be submitted and no more tasks will be executed. */
SESSION_STATUS_PAUSED = 3; /** Session is paused. Tasks can be submitted but no more new tasks will be executed. Already running tasks will continue until they finish. */
SESSION_STATUS_PURGED = 4; /** Session is purged. No more tasks can be submitted and executed. Results data will be deleted. */
SESSION_STATUS_DELETED = 5; /** Session is deleted. No more tasks can be submitted and executed. Sessions, tasks and results metadata associated to the session will be deleted. */
SESSION_STATUS_CLOSED = 4; /** Session is closed. No more tasks can be submitted and executed. */
SESSION_STATUS_PURGED = 5; /** Session is purged. No more tasks can be submitted and executed. Results data will be deleted. */
SESSION_STATUS_DELETED = 6; /** Session is deleted. No more tasks can be submitted and executed. Sessions, tasks and results metadata associated to the session will be deleted. */
}
17 changes: 17 additions & 0 deletions Protos/V1/sessions_common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ message SessionRaw {

google.protobuf.Timestamp created_at = 5; /** The creation date. */
google.protobuf.Timestamp cancelled_at = 6; /** The cancellation date. Only set when status is 'cancelled'. */
google.protobuf.Timestamp closed_at = 12; /** The closure date. Only set when status is 'closed'. */
google.protobuf.Timestamp purged_at = 10; /** The purge date. Only set when status is 'purged'. */
google.protobuf.Timestamp deleted_at = 11; /** The deletion date. Only set when status is 'deleted'. */
google.protobuf.Duration duration = 7; /** The duration. Only set when status is 'cancelled' and 'closed'. */
Expand Down Expand Up @@ -159,6 +160,22 @@ message ResumeSessionResponse {
SessionRaw session = 1; /** The session. */
}

/**
* Request for closing a single session.
*/
message CloseSessionRequest {
string session_id = 1; /** The session ID. */
}

/**
* Response for closing a single session.
*
* Return a raw session.
*/
message CloseSessionResponse {
SessionRaw session = 1; /** The session. */
}

/**
* Request for purging a single session.
*/
Expand Down
3 changes: 3 additions & 0 deletions Protos/V1/sessions_fields.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ enum SessionRawEnumField {
SESSION_RAW_ENUM_FIELD_OPTIONS = 4;
SESSION_RAW_ENUM_FIELD_CREATED_AT = 5;
SESSION_RAW_ENUM_FIELD_CANCELLED_AT = 6;
SESSION_RAW_ENUM_FIELD_CLOSED_AT = 8;
SESSION_RAW_ENUM_FIELD_PURGED_AT = 9;
SESSION_RAW_ENUM_FIELD_DELETED_AT = 10;
SESSION_RAW_ENUM_FIELD_DURATION = 7;
}

Expand Down
5 changes: 5 additions & 0 deletions Protos/V1/sessions_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ service Sessions {
*/
rpc ResumeSession(ResumeSessionRequest) returns (ResumeSessionResponse);

/**
* Close a session by its id..
*/
rpc CloseSession(CloseSessionRequest) returns (CloseSessionResponse);

/**
* Purge a session by its id. Removes Results data.
*/
Expand Down
9 changes: 9 additions & 0 deletions packages/csharp/ArmoniK.Api.Mock/Services/Sessions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ public override Task<ResumeSessionResponse> ResumeSession(ResumeSessionRequest r
Session = MockSession,
});

/// <inheritdoc />
[Count]
public override Task<CloseSessionResponse> CloseSession(CloseSessionRequest request,
ServerCallContext context)
=> Task.FromResult(new CloseSessionResponse
{
Session = MockSession,
});

/// <inheritdoc />
[Count]
public override Task<PurgeSessionResponse> PurgeSession(PurgeSessionRequest request,
Expand Down
17 changes: 16 additions & 1 deletion packages/python/src/armonik/client/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
PauseSessionResponse,
PurgeSessionRequest,
PurgeSessionResponse,
CloseSessionRequest,
CloseSessionResponse,
ResumeSessionRequest,
ResumeSessionResponse,
StopSubmissionRequest,
Expand Down Expand Up @@ -195,6 +197,19 @@ def resume_session(self, session_id: str) -> Session:
response: ResumeSessionResponse = self._client.ResumeSession(request)
return Session.from_message(response.session)

def close_session(self, session_id: str) -> Session:
"""Close a session by its id.
Args:
session_id: Id of the session to be closed.
Returns:
session metadata
"""
request = CloseSessionRequest(session_id=session_id)
response: CloseSessionResponse = self._client.CloseSession(request)
return Session.from_message(response.session)

def purge_session(self, session_id: str) -> Session:
"""Purge a session by its id.
Expand Down Expand Up @@ -234,4 +249,4 @@ def stop_submission_session(self, session_id: str, client: bool, worker:bool) ->
"""
request = StopSubmissionRequest(session_id=session_id, client=client, worker=worker)
response: StopSubmissionResponse = self._client.StopSubmission(request)
return Session.from_message(response.session)
return Session.from_message(response.session)
2 changes: 2 additions & 0 deletions packages/python/src/armonik/common/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class Session:
options: Optional[TaskOptions] = None
created_at: Optional[datetime] = None
cancelled_at: Optional[datetime] = None
closed_at: Optional[datetime] = None
purged_at: Optional[datetime] = None
deleted_at: Optional[datetime] = None
duration: Optional[timedelta] = None
Expand All @@ -208,6 +209,7 @@ def from_message(cls, session_raw: SessionRaw) -> "Session":
options=TaskOptions.from_message(session_raw.options),
created_at=timestamp_to_datetime(session_raw.created_at),
cancelled_at=timestamp_to_datetime(session_raw.cancelled_at),
closed_at=timestamp_to_datetime(session_raw.closed_at),
purged_at=timestamp_to_datetime(session_raw.purged_at),
deleted_at=timestamp_to_datetime(session_raw.deleted_at),
duration=duration_to_timedelta(session_raw.duration),
Expand Down
6 changes: 6 additions & 0 deletions packages/python/tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ def test_purge_session(self):

assert rpc_called("Sessions", "PurgeSession")

def test_close_session(self):
session_client: ArmoniKSessions = get_client("Sessions")
session_client.close_session("session-id")

assert rpc_called("Sessions", "CloseSession")

def test_delete_session(self):
session_client: ArmoniKSessions = get_client("Sessions")
session_client.delete_session("session-id")
Expand Down

0 comments on commit 8d52f10

Please sign in to comment.