feat(gateway): Docker Gateway 봇 + HTTP API 구현 #task-311
- gateway.py: Collector↔Gateway HTTP API (pending, response, chat, register, commands) - Dockerfile + docker-compose.yml: BOT_MODE=gateway, port 8585 - main.py: gateway 모드 (watcher 비활성, GatewayAPI 시작) - config.py: gateway 모드 BRAIN_PATH 검증 스킵 - requirements.txt: aiohttp 추가 - docs/usage-guide.md: Docker 배포 섹션 추가 - Extension VSIX v0.3.9 빌드 (auto-approve 포함)
This commit is contained in:
25
main.py
25
main.py
@@ -6,6 +6,7 @@ Entry point that runs the brain watcher and Discord bot together.
|
||||
import asyncio
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from config import Config
|
||||
@@ -61,7 +62,9 @@ async def main():
|
||||
logger.info(f"Remote transport: {Config.REMOTE_BRIDGE_URL}")
|
||||
|
||||
# Create components
|
||||
watcher = BrainWatcher(event_queue, loop)
|
||||
watcher = None
|
||||
if Config.BOT_MODE != 'gateway':
|
||||
watcher = BrainWatcher(event_queue, loop)
|
||||
bot = GravityBot(event_queue)
|
||||
|
||||
# Inject transport if specified (otherwise bot uses default LocalTransport)
|
||||
@@ -70,9 +73,20 @@ async def main():
|
||||
bot.bridge = BridgeProtocol(transport)
|
||||
|
||||
try:
|
||||
# Start watcher (runs in a separate thread via watchdog)
|
||||
watcher.start()
|
||||
logger.info(f"Watcher started, {len(watcher.known_sessions)} existing sessions")
|
||||
# Start watcher (local mode only — gateway receives data via HTTP)
|
||||
if watcher:
|
||||
watcher.start()
|
||||
logger.info(f"Watcher started, {len(watcher.known_sessions)} existing sessions")
|
||||
else:
|
||||
logger.info("Gateway mode — watcher disabled (data via HTTP API)")
|
||||
|
||||
# Start Gateway HTTP API (gateway mode)
|
||||
if Config.BOT_MODE == 'gateway':
|
||||
from gateway import GatewayAPI
|
||||
gateway_port = int(os.environ.get('GATEWAY_PORT', '8585'))
|
||||
gateway = GatewayAPI(bot, port=gateway_port)
|
||||
await gateway.start()
|
||||
logger.info(f"Gateway API running on port {gateway_port}")
|
||||
|
||||
# Run Discord bot (blocks until bot disconnects)
|
||||
await bot.start(Config.DISCORD_TOKEN)
|
||||
@@ -83,7 +97,8 @@ async def main():
|
||||
logger.error(f"Fatal error: {e}", exc_info=True)
|
||||
finally:
|
||||
# Cleanup
|
||||
watcher.stop()
|
||||
if watcher:
|
||||
watcher.stop()
|
||||
if not bot.is_closed():
|
||||
await bot.close()
|
||||
logger.info("Gravity Control shutdown complete")
|
||||
|
||||
Reference in New Issue
Block a user