тред game обновляется каждые 5 минут за 1ч10мин пока матч не станет ОНЛАЙН. как только онлайн, этот тред гасится

This commit is contained in:
2025-11-04 14:23:21 +03:00
parent 04cc0c5be0
commit aaa4505380

View File

@@ -559,40 +559,36 @@ def results_consumer():
else: else:
if source == "game": if source == "game":
# has_game_already = "teams" in latest_data has_game_already = "game" in latest_data and isinstance(latest_data.get("game"), dict)
has_game_already = "game" in latest_data and isinstance(
latest_data.get("game"), dict
)
# есть ли в ответе ПОЛНАЯ структура # Полная структура?
is_full = ( is_full = (
"data" in payload isinstance(payload, dict)
and "data" in payload
and isinstance(payload["data"], dict) and isinstance(payload["data"], dict)
and "result" in payload["data"] and "teams" in payload["data"]["result"] and "result" in payload["data"]
and "teams" in payload["data"]["result"]
) )
if is_full: # ⚙️ ЛОГИКА:
# полный game — всегда кладём # 1) Пока матч НЕ online (STATUS != 'live'): обновляем всегда,
latest_data["game"] = { # чтобы /status видел "живость" раз в 5 минут независимо от полноты JSON.
"ts": msg["ts"], if globals().get("STATUS") != "live":
"data": payload, latest_data["game"] = {"ts": msg["ts"], "data": payload}
} # можно залогировать для отладки:
logger.debug("results_consumer: pre-live game → updated (full=%s)", is_full)
# 2) Когда матч УЖЕ online (STATUS == 'live'):
# - поток 'game' в live-режиме погаснет сам (stop_when_live=True),
# но если вдруг что-то долетит, кладём только полный JSON.
else: else:
if ( if is_full:
globals().get("STATUS") in ("live", "live_soon") latest_data["game"] = {"ts": msg["ts"], "data": payload}
and has_game_already logger.debug("results_consumer: LIVE & full game → replaced")
):
logger.debug(
"results_consumer: LIVE & partial game → keep previous one"
)
else: else:
if not has_game_already: # Ничего не трогаем, чтобы не затереть полноценные данные пустотой.
# раньше не было вообще — положим хоть что-то logger.debug("results_consumer: LIVE & partial game → keep previous one")
latest_data["game"] = {"ts": msg["ts"], "data": payload} continue
else:
logger.debug(
"results_consumer: got partial game, keeping previous one"
)
# # game неполный # # game неполный
# if not has_game_already: # if not has_game_already:
# # 👉 раньше game вообще не было — лучше положить хоть что-то # # 👉 раньше game вообще не было — лучше положить хоть что-то