fix(B2): _busy_started_at Reset-Logik korrigiert — keine künstliche Honeymoon-Verlängerung
This commit is contained in:
@@ -246,8 +246,12 @@ class PresenceEngine:
|
||||
with self._busy_honeymoon_lock:
|
||||
self._busy_counter += 1
|
||||
if self._busy_honeymoon_timer is None:
|
||||
# First busy start — record time and start honeymoon timer
|
||||
self._busy_started_at = time.monotonic()
|
||||
# B2: _busy_started_at nur beim ERSTEN busy-Start setzen.
|
||||
# Wenn der Honeymoon-Timer bereits abgelaufen ist (Timer=None)
|
||||
# aber _busy_started_at noch existiert (weil active > 0),
|
||||
# dann NICHT neu setzen — sonst künstliche Verlängerung um 1s.
|
||||
if self._busy_started_at == 0.0:
|
||||
self._busy_started_at = time.monotonic()
|
||||
self._busy_honeymoon_timer = threading.Timer(
|
||||
self.MIN_BUSY_VISIBLE_S,
|
||||
self._honeymoon_expired,
|
||||
@@ -255,8 +259,8 @@ class PresenceEngine:
|
||||
self._busy_honeymoon_timer.daemon = True
|
||||
self._busy_honeymoon_timer.start()
|
||||
logger.debug(
|
||||
"[presence] Honeymoon-Timer gestartet (%.1fs), counter=%d",
|
||||
self.MIN_BUSY_VISIBLE_S, self._busy_counter,
|
||||
"[presence] Honeymoon-Timer gestartet (%.1fs), counter=%d, started_at=%.3f",
|
||||
self.MIN_BUSY_VISIBLE_S, self._busy_counter, self._busy_started_at,
|
||||
)
|
||||
else:
|
||||
logger.debug(
|
||||
@@ -308,6 +312,8 @@ class PresenceEngine:
|
||||
|
||||
Called by threading.Timer after MIN_BUSY_VISIBLE_S.
|
||||
If no active tasks remain, sets status to online.
|
||||
B3: Checks pending_status under _active_tasks_lock to prevent
|
||||
race with mark_busy_started.
|
||||
"""
|
||||
with self._busy_honeymoon_lock:
|
||||
self._busy_honeymoon_timer = None
|
||||
@@ -316,6 +322,9 @@ class PresenceEngine:
|
||||
active = self._active_tasks
|
||||
|
||||
if active == 0:
|
||||
# B2: Reset _busy_started_at when honeymoon fully expires
|
||||
# and no active tasks remain — next busy cycle starts fresh.
|
||||
self._busy_started_at = 0.0
|
||||
logger.info(
|
||||
"[presence] Honeymoon-Timer abgelaufen, active_tasks=0 → online"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user