Fix bugs issues
This commit is contained in:
@@ -1,9 +1,38 @@
|
||||
"""
|
||||
Messaging service for training service
|
||||
Training service messaging - Uses shared RabbitMQ client only
|
||||
"""
|
||||
|
||||
from shared.messaging.rabbitmq import RabbitMQClient
|
||||
from app.core.config import settings
|
||||
import logging
|
||||
|
||||
# Global message publisher
|
||||
message_publisher = RabbitMQClient(settings.RABBITMQ_URL)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Single global instance
|
||||
training_publisher = RabbitMQClient(settings.RABBITMQ_URL, "training-service")
|
||||
|
||||
async def setup_messaging():
|
||||
"""Initialize messaging for training service"""
|
||||
success = await training_publisher.connect()
|
||||
if success:
|
||||
logger.info("Training service messaging initialized")
|
||||
else:
|
||||
logger.warning("Training service messaging failed to initialize")
|
||||
|
||||
async def cleanup_messaging():
|
||||
"""Cleanup messaging for training service"""
|
||||
await training_publisher.disconnect()
|
||||
logger.info("Training service messaging cleaned up")
|
||||
|
||||
# Convenience functions for training-specific events
|
||||
async def publish_training_started(data: dict) -> bool:
|
||||
"""Publish training started event"""
|
||||
return await training_publisher.publish_training_event("started", data)
|
||||
|
||||
async def publish_training_completed(data: dict) -> bool:
|
||||
"""Publish training completed event"""
|
||||
return await training_publisher.publish_training_event("completed", data)
|
||||
|
||||
async def publish_training_failed(data: dict) -> bool:
|
||||
"""Publish training failed event"""
|
||||
return await training_publisher.publish_training_event("failed", data)
|
||||
|
||||
Reference in New Issue
Block a user