Skip to content

Commit

Permalink
feat: portal sigterm handler
Browse files Browse the repository at this point in the history
  • Loading branch information
supersergiy committed Feb 18, 2025
1 parent 0eab435 commit a5e5d62
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions zetta_utils/mazepa/progress_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from rich.console import Console

from zetta_utils.common import custom_signal_handler_ctx, get_user_confirmation
from zetta_utils.common.ctx_managers import noop_ctx_mngr

from .execution_state import ProgressReport

Expand Down Expand Up @@ -42,6 +41,10 @@ def handler(_, __):
return handler


def graceful_shutdown(_, __): # pragma: no cover
sys.exit(0)


class ProgressUpdateFN(Protocol):
def __call__(self, progress_reports: dict[str, ProgressReport]) -> None:
...
Expand Down Expand Up @@ -98,7 +101,7 @@ def custom_debugger_hook():
get_confirm_sigint_fn(progress_bar), signal.SIGINT
)
else:
handler_ctx = noop_ctx_mngr()
handler_ctx = custom_signal_handler_ctx(graceful_shutdown, signal.SIGTERM)
with handler_ctx:
submission_tracker_ids = {
k: progress_bar.add_task(
Expand Down
2 changes: 2 additions & 0 deletions zetta_utils/mazepa_addons/configurations/execute_locally.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def execute_locally(
semaphores_spec: dict[SemaphoreType, int] | None = None,
debug: bool = False,
write_progress_summary: bool = False,
require_interrupt_confirm: bool = True,
):

queues_dir_ = queues_dir if queues_dir else ""
Expand Down Expand Up @@ -75,4 +76,5 @@ def execute_locally(
checkpoint_interval_sec=checkpoint_interval_sec,
raise_on_failed_checkpoint=raise_on_failed_checkpoint,
write_progress_summary=write_progress_summary,
require_interrupt_confirm=require_interrupt_confirm,
)
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def execute_on_gcp_with_sqs( # pylint: disable=too-many-locals
checkpoint_interval_sec: float = 300.0,
raise_on_failed_checkpoint: bool = True,
write_progress_summary: bool = False,
require_interrupt_confirm: bool = True,
):
if debug and not local_test:
raise ValueError("`debug` can only be set to `True` when `local_test` is also `True`.")
Expand All @@ -245,6 +246,7 @@ def execute_on_gcp_with_sqs( # pylint: disable=too-many-locals
semaphores_spec=semaphores_spec,
debug=debug,
write_progress_summary=write_progress_summary,
require_interrupt_confirm=require_interrupt_confirm,
)
else:
assert gcloud.check_image_exists(worker_image), worker_image
Expand Down Expand Up @@ -306,5 +308,5 @@ def execute_on_gcp_with_sqs( # pylint: disable=too-many-locals
checkpoint_interval_sec=checkpoint_interval_sec,
raise_on_failed_checkpoint=raise_on_failed_checkpoint,
write_progress_summary=write_progress_summary,
require_interrupt_confirm=False,
require_interrupt_confirm=require_interrupt_confirm,
)

0 comments on commit a5e5d62

Please sign in to comment.