Skip to content

Commit

Permalink
feat: introduce ListApplications and DeleteApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Apr 30, 2024
1 parent 31885dc commit e74ebd7
Show file tree
Hide file tree
Showing 7 changed files with 799 additions and 1,211 deletions.
59 changes: 49 additions & 10 deletions projects/fal/src/fal/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ class HostedRunStatus:
state: HostedRunState


@dataclass
class ApplicationInfo:
application_id: str
auth_mode: str
keep_alive: int
max_concurrency: int
max_multiplexing: int
active_runners: int
min_concurrency: int


@dataclass
class AliasInfo:
alias: str
Expand Down Expand Up @@ -262,22 +273,38 @@ def from_proto(
else:
raise ValueError(f"Unknown KeyScope: {proto}")

def _get_auth_mode(auth_mode):
if auth_mode is isolate_proto.ApplicationAuthMode.PUBLIC:
return "public"

if auth_mode is isolate_proto.ApplicationAuthMode.PRIVATE:
return "private"

if auth_mode is isolate_proto.ApplicationAuthMode.SHARED:
return "shared"

raise ValueError(f"Unknown auth mode: {auth_mode}")


@from_grpc.register(isolate_proto.ApplicationInfo)
def _from_grpc_application_info(message: isolate_proto.ApplicationInfo) -> ApplicationInfo:
return ApplicationInfo(
application_id=message.application_id,
auth_mode=_get_auth_mode(message.auth_mode),
keep_alive=message.keep_alive,
max_concurrency=message.max_concurrency,
max_multiplexing=message.max_multiplexing,
active_runners=message.active_runners,
min_concurrency=message.min_concurrency,
)


@from_grpc.register(isolate_proto.AliasInfo)
def _from_grpc_alias_info(message: isolate_proto.AliasInfo) -> AliasInfo:
if message.auth_mode is isolate_proto.ApplicationAuthMode.PUBLIC:
auth_mode = "public"
elif message.auth_mode is isolate_proto.ApplicationAuthMode.PRIVATE:
auth_mode = "private"
elif message.auth_mode is isolate_proto.ApplicationAuthMode.SHARED:
auth_mode = "shared"
else:
raise ValueError(f"Unknown auth mode: {message.auth_mode}")

return AliasInfo(
alias=message.alias,
revision=message.revision,
auth_mode=auth_mode,
auth_mode=_get_auth_mode(message._auth_mode),
keep_alive=message.keep_alive,
max_concurrency=message.max_concurrency,
max_multiplexing=message.max_multiplexing,
Expand Down Expand Up @@ -496,6 +523,18 @@ def update_application(
)
return from_grpc(res.alias_info)

def list_applications(self) -> list[ApplicationInfo]:
request = isolate_proto.ListApplicationsRequest()
response: isolate_proto.ListApplicationsResult = self.stub.ListApplications(request)
return [from_grpc(app) for app in response.applications]

def delete_application(
self,
application_id: str,
) -> None:
request = isolate_proto.DeleteApplicationRequest(application_id=application_id)
self.stub.DeleteApplication(request)

def run(
self,
function: Callable[..., ResultT],
Expand Down
1 change: 1 addition & 0 deletions projects/isolate_proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ For regenerating definitions:

```
$ cd projects/isolate_proto
$ pip install '.[dev]'
$ python ../../tools/regen_grpc.py src/isolate_proto/controller.proto <isolate version>
$ pre-commit run --all-files
```
Expand Down
4 changes: 4 additions & 0 deletions projects/isolate_proto/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ test = [
]
dev = [
"isolate_proto[test]",
# for tools/regen_grpc.py
"refactor",
"grpcio-tools",
"mypy-protobuf",
]
30 changes: 30 additions & 0 deletions projects/isolate_proto/src/isolate_proto/controller.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ service IsolateController {
rpc RegisterApplication (RegisterApplicationRequest) returns (stream RegisterApplicationResult) {};
// Update configuration of an existing application.
rpc UpdateApplication (UpdateApplicationRequest) returns (UpdateApplicationResult) {};
// List functions
rpc ListApplications (ListApplicationsRequest) returns (ListApplicationsResult) {};
// Delete a function
rpc DeleteApplication (DeleteApplicationRequest) returns (DeleteApplicationResult) {};
// Set alias to point to an existing application.
rpc SetAlias (SetAliasRequest) returns (SetAliasResult) {};
// Delete an alias.
Expand Down Expand Up @@ -197,6 +201,32 @@ message UpdateApplicationResult {
AliasInfo alias_info = 1;
}

message ListApplicationsRequest {
// Empty. For future use.
}

message ApplicationInfo {
string application_id = 1;
ApplicationAuthMode auth_mode = 2;
int32 max_concurrency = 3;
int32 max_multiplexing = 4;
int32 keep_alive = 5;
int32 active_runners = 6;
int32 min_concurrency = 7;
}

message ListApplicationsResult {
repeated ApplicationInfo applications = 1;
}

message DeleteApplicationRequest {
string application_id = 1;
}

message DeleteApplicationResult {
// Empty. For future use.
}

message SetAliasRequest {
string alias = 1;
string revision = 2;
Expand Down
178 changes: 92 additions & 86 deletions projects/isolate_proto/src/isolate_proto/controller_pb2.py

Large diffs are not rendered by default.

Loading

0 comments on commit e74ebd7

Please sign in to comment.