feat(queue): integrate redis queue and 2-minute paced ai consumer worker
This commit is contained in:
@@ -8,6 +8,8 @@ from db.database import init_db, close_db_pool
|
||||
from db.repository import Repository
|
||||
from core.metrics import start_metrics_server
|
||||
from core.llm import LLMClient
|
||||
from core.queue import RedisQueue
|
||||
from services.queue_consumer import QueueConsumerService
|
||||
from services.ai_processor import AIProcessor
|
||||
from services.collector import CollectorService
|
||||
from services.admin_bot import AdminBotService
|
||||
@@ -30,10 +32,13 @@ async def main():
|
||||
metrics_port = int(os.getenv("METRICS_PORT", "8000"))
|
||||
start_metrics_server(metrics_port)
|
||||
|
||||
# 2. Initialize Database schema
|
||||
# 2. Initialize Database schema & Redis Queue
|
||||
await init_db()
|
||||
logger.info("Database schema initialized.")
|
||||
|
||||
redis_queue = RedisQueue()
|
||||
await redis_queue.connect()
|
||||
|
||||
repo = Repository()
|
||||
llm = LLMClient()
|
||||
|
||||
@@ -50,13 +55,15 @@ async def main():
|
||||
return post
|
||||
ai_processor.process_post = process_and_notify
|
||||
|
||||
collector = CollectorService(repo=repo, ai_processor=ai_processor)
|
||||
collector = CollectorService(repo=repo, ai_processor=ai_processor, queue=redis_queue)
|
||||
admin_bot.set_collector(collector)
|
||||
publisher = PublisherService(repo=repo)
|
||||
queue_consumer = QueueConsumerService(queue=redis_queue, ai_processor=ai_processor)
|
||||
|
||||
# 4. Start all services
|
||||
await admin_bot.start()
|
||||
await collector.start(notify_fn=admin_bot.notify_admins)
|
||||
await queue_consumer.start()
|
||||
await publisher.start()
|
||||
|
||||
logger.info("All Copykar services are active and running.")
|
||||
@@ -78,8 +85,10 @@ async def main():
|
||||
finally:
|
||||
logger.info("Shutting down Copykar services...")
|
||||
await collector.stop()
|
||||
await queue_consumer.stop()
|
||||
await publisher.stop()
|
||||
await admin_bot.stop()
|
||||
await redis_queue.close()
|
||||
await close_db_pool()
|
||||
logger.info("Copykar cleanly shut down.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user