Skip to content

Commit 4237897

Browse files
committed
refactor: extract safety timeout magic numbers into named constants
Replace magic numbers 15 and 30 in _cleanup_after_lease with named constants DEFAULT_SAFETY_TIMEOUT_SECONDS and HOOK_TIMEOUT_MARGIN_SECONDS to improve clarity of the timeout calculation. Generated-By: Forge/20260420_160310_819241_5043dbb0
1 parent f32f73d commit 4237897

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

  • python/packages/jumpstarter/jumpstarter/exporter

python/packages/jumpstarter/jumpstarter/exporter/exporter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
logger = logging.getLogger(__name__)
3737

38+
DEFAULT_SAFETY_TIMEOUT_SECONDS = 15
39+
HOOK_TIMEOUT_MARGIN_SECONDS = 30
40+
3841

3942
async def _standalone_shutdown_waiter():
4043
"""Wait forever; used so serve_standalone_tcp can be cancelled by stop()."""
@@ -606,12 +609,12 @@ async def _cleanup_after_lease(self, lease_scope: LeaseContext) -> None:
606609
# was never set due to a race (e.g. conn_tg cancelled early).
607610
# Use the configured hook timeout (+ margin) when available so we
608611
# never interrupt a legitimately-running beforeLease hook.
609-
safety_timeout = 15 # generous default for no-hook / unknown cases
612+
safety_timeout = DEFAULT_SAFETY_TIMEOUT_SECONDS
610613
if (
611614
self.hook_executor
612615
and self.hook_executor.config.before_lease
613616
):
614-
safety_timeout = self.hook_executor.config.before_lease.timeout + 30
617+
safety_timeout = self.hook_executor.config.before_lease.timeout + HOOK_TIMEOUT_MARGIN_SECONDS
615618
with move_on_after(safety_timeout) as timeout_scope:
616619
await lease_scope.before_lease_hook.wait()
617620
if timeout_scope.cancelled_caught:

0 commit comments

Comments
 (0)