Enhance caching mechanism and logging configuration
- Updated .gitignore to include additional IDE and OS files, as well as log and web build directories. - Expanded config.sample.yaml to include cache configuration options for memory and Redis. - Modified wallamonitor.py to load cache configuration and initialize ArticleCache. - Refactored QueueManager to utilize ArticleCache for tracking notified articles. - Improved logging setup to dynamically determine log file path based on environment.
This commit is contained in:
@@ -5,15 +5,14 @@ import logging
|
||||
from managers.telegram_manager import TelegramManager
|
||||
|
||||
MESSAGE_DELAY = 3.0 # Tiempo de espera entre mensajes en segundos
|
||||
NOTIFIED_ARTICLES_LIMIT = 300 # Límite de artículos notificados a mantener en memoria
|
||||
RETRY_TIMES = 3
|
||||
|
||||
class QueueManager:
|
||||
def __init__(self):
|
||||
def __init__(self, article_cache):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self._queue = queue.Queue() # Cola thread-safe
|
||||
self._notified_articles = []
|
||||
self._telegram_manager = TelegramManager()
|
||||
self._article_cache = article_cache
|
||||
self._running = True
|
||||
|
||||
# Iniciar el thread de procesamiento
|
||||
@@ -22,7 +21,7 @@ class QueueManager:
|
||||
|
||||
def add_to_queue(self, article, search_name=None, thread_id=None, retry_times=RETRY_TIMES):
|
||||
# Verificar si el artículo ya ha sido enviado
|
||||
if article in self._notified_articles:
|
||||
if self._article_cache.is_article_notified(article):
|
||||
return
|
||||
|
||||
if search_name is None:
|
||||
@@ -30,14 +29,11 @@ class QueueManager:
|
||||
self._queue.put((search_name, article, thread_id, retry_times))
|
||||
self.logger.debug(f"Artículo añadido a la cola: {article.get_title()}")
|
||||
|
||||
self.add_to_notified_articles(article)
|
||||
self._article_cache.mark_article_as_notified(article)
|
||||
|
||||
def add_to_notified_articles(self, articles):
|
||||
"""Añade artículos a la lista de artículos ya notificados"""
|
||||
if isinstance(articles, list):
|
||||
self._notified_articles.extend(articles)
|
||||
else:
|
||||
self._notified_articles.append(articles)
|
||||
self._article_cache.mark_articles_as_notified(articles)
|
||||
|
||||
def _process_queue(self):
|
||||
self.logger.info("Procesador de cola: Iniciado")
|
||||
|
||||
Reference in New Issue
Block a user