fix(bot): early exit for processed posts

This commit is contained in:
2026-07-29 23:13:38 +05:00
parent 51f6e417bd
commit f0f9932420
2 changed files with 21 additions and 12 deletions
+2
View File
@@ -28,9 +28,11 @@ async def main():
except (ValueError, TypeError) as e:
logger.critical(f"Ошибка в конфигурации или при запуске: {e}")
raise
except Exception as e:
logger.critical(f"Фатальная ошибка при запуске бота: {e}")
raise
if __name__ == "__main__":
+19 -12
View File
@@ -132,10 +132,10 @@ class TelegramStarsBot:
if attempt < self.config.max_retries - 1:
await asyncio.sleep(3 * (attempt + 1))
logger.error(
f"Все {self.config.max_retries} попытки отправки звезд в https://t.me/{channel} исчерпаны."
)
return False
logger.error(
f"Все {self.config.max_retries} попытки отправки звезд в https://t.me/{channel} исчерпаны."
)
return False
except Exception as e:
logger.error(f"Критическая ошибка при отправке звезд: {e}")
@@ -145,18 +145,21 @@ class TelegramStarsBot:
post_message_id = None
post_id = post.get("post_id")
if not post_id:
logger.warning("Пост без post_id, пропускаю.")
return
if self.processed_manager.is_processed(post_id):
logger.debug(f"Пост {post_id} уже обработан, пропускаю.")
return
# Only fetch full post data for unprocessed posts
post = await self.lolz_api.get_post(post_id=post_id)
poster_user_id = post.get("poster_user_id")
poster_username = post.get("poster_username", "Неизвестный пользователь")
if not post_id or self.processed_manager.is_processed(post_id):
if post_id:
logger.debug(f"Пост {post_id} уже обработан, пропускаю.")
else:
logger.warning("Пост без post_id, пропускаю.")
return
logger.info(
f"Найден новый пост для обработки: ID {post_id} (от {poster_username})"
)
@@ -264,7 +267,11 @@ class TelegramStarsBot:
if posts:
for post in posts:
await self._process_single_post(post)
try:
await self._process_single_post(post)
except Exception as e:
post_id = post.get("post_id", "?")
logger.error(f"Ошибка обработки поста {post_id}, пропускаю: {e}")
if last_page > self.start_page:
logger.info(f"Мониторинг продвинулся до страницы {last_page}.")
self.start_page = last_page