mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-08-28 10:21:17 +00:00
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
|
|
|
"""Configuration helpers for optional long-running execution guards."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from app.component.environment import env
|
|
|
|
logger = logging.getLogger("run_runtime.timeout_config")
|
|
|
|
|
|
def normalize_optional_timeout_seconds(value: float) -> float | None:
|
|
"""Return a positive timeout, or ``None`` when the guard is disabled."""
|
|
|
|
return float(value) if value > 0 else None
|
|
|
|
|
|
def optional_timeout_seconds_from_env(
|
|
name: str,
|
|
*,
|
|
default: float = 0,
|
|
) -> float | None:
|
|
"""Read an opt-in timeout whose non-positive value means no hard cap."""
|
|
|
|
raw = env(name, str(default))
|
|
try:
|
|
value = float(raw)
|
|
except (TypeError, ValueError):
|
|
logger.warning(
|
|
"Invalid %s value %r; using default %s",
|
|
name,
|
|
raw,
|
|
default,
|
|
)
|
|
value = default
|
|
return normalize_optional_timeout_seconds(value)
|