app: update service orchestration, environment configs, and documentation

This commit is contained in:
mamad
2026-08-28 19:35:02 +03:30
parent 55c9c2a4cf
commit ad4c111318
6 changed files with 178 additions and 9 deletions
+24 -6
View File
@@ -28,9 +28,10 @@ async def main():
logger.info("Starting Copykar System with Immediate Admin Review & Paced Target Queues...")
# 1. Start Prometheus metrics server
metrics_port = int(os.getenv("METRICS_PORT", "8000"))
metrics_port = int(os.getenv("METRICS_PORT", "8008"))
start_metrics_server(metrics_port)
# 2. Initialize Database schema & Redis Queue
await init_db()
logger.info("Database schema initialized.")
@@ -39,16 +40,29 @@ async def main():
await redis_queue.connect()
repo = Repository()
llm = LLMClient()
await repo.ensure_default_providers()
# 3. Create Services
admin_bot = AdminBotService(repo=repo, queue=redis_queue)
llm = LLMClient(
repo=repo,
on_fallback_alert=admin_bot.on_ai_fallback_alert,
on_chain_failure_alert=admin_bot.on_ai_chain_failure_alert
)
ai_processor = AIProcessor(repo=repo, llm=llm)
admin_bot = AdminBotService(repo=repo, ai_processor=ai_processor, queue=redis_queue)
collector = CollectorService(repo=repo, on_post_received=admin_bot.send_raw_review_post)
admin_bot.set_ai_processor(ai_processor)
collector = CollectorService(repo=repo, on_post_received=admin_bot.handle_collected_post)
admin_bot.set_collector(collector)
# Publisher handles per-target delivery queues, intervals, and sleep windows
publisher = PublisherService(repo=repo, queue=redis_queue, client=collector.client)
# Publisher handles per-target delivery queues, intervals, and sleep windows.
# Delivery goes out over the bot account so target channels only need to grant
# posting rights to the bot, never to the personal userbot account.
publisher = PublisherService(
repo=repo,
queue=redis_queue,
client=admin_bot.client,
notify_fn=admin_bot.notify_admins,
)
# 4. Start all services
await admin_bot.start()
@@ -56,6 +70,10 @@ async def main():
await publisher.start()
logger.info("All Copykar services are active and running.")
try:
await admin_bot.broadcast_change_notes()
except Exception as e:
logger.debug(f"Could not broadcast change notes on startup: {e}")
# Graceful shutdown event
stop_event = asyncio.Event()