Skip to content

Commit

Permalink
feat: introduce List and Cancel (#146)
Browse files Browse the repository at this point in the history
* feat: introduce List and Cancel

* Task -> RunTask

Per #146 (comment)
  • Loading branch information
efiop authored Jun 27, 2024
1 parent 1b4687b commit 9c10d0a
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 45 deletions.
26 changes: 25 additions & 1 deletion src/isolate/server/definitions/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ service Isolate {

// Submit a function to be run without waiting for results.
rpc Submit (SubmitRequest) returns (SubmitResponse) {}

// List running tasks
rpc List (ListRequest) returns (ListResponse) {}

// Cancel a running task
rpc Cancel (CancelRequest) returns (CancelResponse) {}
}

message BoundFunction {
Expand All @@ -33,5 +39,23 @@ message SubmitRequest {
}

message SubmitResponse {
// Reserved for future use.
string task_id = 1;
}

message ListRequest {
}

message TaskInfo {
string task_id = 1;
}

message ListResponse {
repeated TaskInfo tasks = 1;
}

message CancelRequest {
string task_id = 1;
}

message CancelResponse {
}
18 changes: 14 additions & 4 deletions src/isolate/server/definitions/server_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 71 additions & 2 deletions src/isolate/server/definitions/server_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,81 @@ global___SubmitRequest = SubmitRequest

@typing.final
class SubmitResponse(google.protobuf.message.Message):
"""Reserved for future use."""

DESCRIPTOR: google.protobuf.descriptor.Descriptor

TASK_ID_FIELD_NUMBER: builtins.int
task_id: builtins.str
def __init__(
self,
*,
task_id: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["task_id", b"task_id"]) -> None: ...

global___SubmitResponse = SubmitResponse

@typing.final
class ListRequest(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

def __init__(
self,
) -> None: ...

global___ListRequest = ListRequest

@typing.final
class TaskInfo(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

TASK_ID_FIELD_NUMBER: builtins.int
task_id: builtins.str
def __init__(
self,
*,
task_id: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["task_id", b"task_id"]) -> None: ...

global___TaskInfo = TaskInfo

@typing.final
class ListResponse(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

TASKS_FIELD_NUMBER: builtins.int
@property
def tasks(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___TaskInfo]: ...
def __init__(
self,
*,
tasks: collections.abc.Iterable[global___TaskInfo] | None = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["tasks", b"tasks"]) -> None: ...

global___ListResponse = ListResponse

@typing.final
class CancelRequest(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

TASK_ID_FIELD_NUMBER: builtins.int
task_id: builtins.str
def __init__(
self,
*,
task_id: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["task_id", b"task_id"]) -> None: ...

global___CancelRequest = CancelRequest

@typing.final
class CancelResponse(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

def __init__(
self,
) -> None: ...

global___CancelResponse = CancelResponse
88 changes: 88 additions & 0 deletions src/isolate/server/definitions/server_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def __init__(self, channel):
request_serializer=server__pb2.SubmitRequest.SerializeToString,
response_deserializer=server__pb2.SubmitResponse.FromString,
_registered_method=True)
self.List = channel.unary_unary(
'/Isolate/List',
request_serializer=server__pb2.ListRequest.SerializeToString,
response_deserializer=server__pb2.ListResponse.FromString,
_registered_method=True)
self.Cancel = channel.unary_unary(
'/Isolate/Cancel',
request_serializer=server__pb2.CancelRequest.SerializeToString,
response_deserializer=server__pb2.CancelResponse.FromString,
_registered_method=True)


class IsolateServicer(object):
Expand All @@ -70,6 +80,20 @@ def Submit(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def List(self, request, context):
"""List running tasks
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def Cancel(self, request, context):
"""Cancel a running task
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_IsolateServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand All @@ -83,6 +107,16 @@ def add_IsolateServicer_to_server(servicer, server):
request_deserializer=server__pb2.SubmitRequest.FromString,
response_serializer=server__pb2.SubmitResponse.SerializeToString,
),
'List': grpc.unary_unary_rpc_method_handler(
servicer.List,
request_deserializer=server__pb2.ListRequest.FromString,
response_serializer=server__pb2.ListResponse.SerializeToString,
),
'Cancel': grpc.unary_unary_rpc_method_handler(
servicer.Cancel,
request_deserializer=server__pb2.CancelRequest.FromString,
response_serializer=server__pb2.CancelResponse.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'Isolate', rpc_method_handlers)
Expand Down Expand Up @@ -147,3 +181,57 @@ def Submit(request,
timeout,
metadata,
_registered_method=True)

@staticmethod
def List(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/Isolate/List',
server__pb2.ListRequest.SerializeToString,
server__pb2.ListResponse.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)

@staticmethod
def Cancel(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/Isolate/Cancel',
server__pb2.CancelRequest.SerializeToString,
server__pb2.CancelResponse.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
Loading

0 comments on commit 9c10d0a

Please sign in to comment.