Skip to content

Commit

Permalink
feat(fal): introduce fal machine kill
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Nov 27, 2024
1 parent add676b commit 32e9aa7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
43 changes: 43 additions & 0 deletions projects/fal/src/fal/cli/machine.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions projects/fal/src/fal/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fal.console import console
from fal.console.icons import CROSS_ICON

from . import apps, auth, create, deploy, doctor, keys, run, secrets
from . import apps, auth, create, deploy, doctor, keys, machine, run, secrets
from .debug import debugtools, get_debug_parser
from .parser import FalParser, FalParserExit

Expand All @@ -31,7 +31,7 @@ def _get_main_parser() -> argparse.ArgumentParser:
required=True,
)

for cmd in [auth, apps, deploy, run, keys, secrets, doctor, create]:
for cmd in [auth, apps, deploy, run, keys, secrets, doctor, create, machine]:
cmd.add_parser(subparsers, parents)

return parser
Expand Down
4 changes: 4 additions & 0 deletions projects/fal/src/fal/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 32e9aa7

Please sign in to comment.