тред 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:
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 = (
"data" in payload
isinstance(payload, dict)
and "data" in payload
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 — всегда кладём
latest_data["game"] = {
"ts": msg["ts"],
"data": payload,
}
# ⚙️ ЛОГИКА:
# 1) Пока матч НЕ online (STATUS != 'live'): обновляем всегда,
# чтобы /status видел "живость" раз в 5 минут независимо от полноты JSON.
if globals().get("STATUS") != "live":
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:
if (
globals().get("STATUS") in ("live", "live_soon")
and has_game_already
):
logger.debug(
"results_consumer: LIVE & partial game → keep previous one"
)
if is_full:
latest_data["game"] = {"ts": msg["ts"], "data": payload}
logger.debug("results_consumer: LIVE & full game → replaced")
else:
if not has_game_already:
# раньше не было вообще — положим хоть что-то
latest_data["game"] = {"ts": msg["ts"], "data": payload}
else:
logger.debug(
"results_consumer: got partial game, keeping previous one"
)
# Ничего не трогаем, чтобы не затереть полноценные данные пустотой.
logger.debug("results_consumer: LIVE & partial game → keep previous one")
continue
# # game неполный
# if not has_game_already:
# # 👉 раньше game вообще не было — лучше положить хоть что-то