Files
zhenxun_bot/zhenxun/services/message_load.py
T

25 lines
512 B
Python
Raw Normal View History

from __future__ import annotations
import time
_OVERLOAD_UNTIL = 0.0
def signal_overload(duration: float = 5.0) -> None:
"""Mark the system as overloaded for a short time window."""
global _OVERLOAD_UNTIL
if duration <= 0:
return
now = time.monotonic()
until = now + duration
if until > _OVERLOAD_UNTIL:
_OVERLOAD_UNTIL = until
def is_overloaded() -> bool:
return time.monotonic() < _OVERLOAD_UNTIL
def should_pause_tasks() -> bool:
return is_overloaded()