From bcef95b89652057471e7f51a6c8c990cbab25257 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 31 Oct 2024 04:07:02 +0200 Subject: [PATCH] feat(fal): introduce fal machine kill --- projects/fal/src/fal/cli/machine.py | 43 +++++++++++++++++++++++++++++ projects/fal/src/fal/sdk.py | 4 +++ 2 files changed, 47 insertions(+) create mode 100644 projects/fal/src/fal/cli/machine.py diff --git a/projects/fal/src/fal/cli/machine.py b/projects/fal/src/fal/cli/machine.py new file mode 100644 index 00000000..1b43b840 --- /dev/null +++ b/projects/fal/src/fal/cli/machine.py @@ -0,0 +1,43 @@ +from .parser import FalClientParser + + +def _kill(args): + from fal.sdk import FalServerlessClient + + client = FalServerlessClient(args.host) + with client.connect() as connection: + connection.kill_runner(args.id) + + +def _add_kill_parser(subparsers, parents): + kill_help = "Kill a machine." + parser = subparsers.add_parser( + "kill", + description=kill_help, + help=kill_help, + parents=parents, + ) + parser.add_argument( + "id", + help="Runner ID.", + ) + parser.set_defaults(func=_kill) + + +def add_parser(main_subparsers, parents): + machine_help = "Manage fal machines." + parser = main_subparsers.add_parser( + "machine", + description=machine_help, + help=machine_help, + parents=parents, + ) + + subparsers = parser.add_subparsers( + title="Commands", + metavar="command", + required=True, + parser_class=FalClientParser, + ) + + _add_kill_parser(subparsers, parents) diff --git a/projects/fal/src/fal/sdk.py b/projects/fal/src/fal/sdk.py index 971c80e0..6a631e82 100644 --- a/projects/fal/src/fal/sdk.py +++ b/projects/fal/src/fal/sdk.py @@ -686,3 +686,7 @@ def list_secrets(self) -> list[ServerlessSecret]: ) for secret in response.secrets ] + + def kill_runner(self, runner_id: str) -> None: + request = isolate_proto.KillRunnerRequest(runner_id=runner_id) + self.stub.KillRunner(request)