Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selective shutdown #18

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion domino_maintenance_mode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ async def _async_snapshot(output, **kwargs):
json.dump(state, output)


def validate_services(ctx, param, value):
if not value:
return None
elif value not in __get_execution_interfaces().keys():
raise click.BadParameter(
"Services must be one of "
f"{list(__get_execution_interfaces().keys())}"
)
else:
return value


@click.command()
@click.argument("snapshot", type=click.File("r"))
@click.option(
Expand Down Expand Up @@ -138,17 +150,31 @@ async def _async_snapshot(output, **kwargs):
default=600,
help="Amount of time to wait for executions to complete.",
)
@click.option(
"-s",
"--service",
type=str,
help="(Optional) Service to shutdown. Options are: "
f"{list(__get_execution_interfaces().keys())}",
callback=validate_services,
)
def shutdown(snapshot, **kwargs):
"""Stop running Apps, Model APIs, Durable Workspaces, and Scheduled Jobs.

SNAPSHOT : The path to snapshot output from 'dmm snapshot'.
"""
state = __load_state(snapshot)
manager = Manager(**kwargs)
for interface in __get_execution_interfaces().values():
if manager.get_service():
interface = __get_execution_interfaces()[manager.get_service()]
executions = state[interface.singular()]
if len(executions) > 0:
manager.stop(interface, executions)
else:
for interface in __get_execution_interfaces().values():
executions = state[interface.singular()]
if len(executions) > 0:
manager.stop(interface, executions)


cli.add_command(shutdown)
Expand Down
5 changes: 5 additions & 0 deletions domino_maintenance_mode/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Manager:

def __init__(
self,
service: str = None,
batch_size: int = 5,
batch_interval_s: int = 5,
max_failures: int = 5,
Expand All @@ -37,6 +38,10 @@ def __init__(
self.batch_interval_s = batch_interval_s
self.grace_period_s = grace_period_s
self.max_failures = max_failures
self.service = service

def get_service(self):
return self.service

def stop(self, interface: ExecutionInterface, executions: List[Execution]):
self.__toggle_executions(
Expand Down
Loading