Add POI feature and imporve the overall backend implementation
This commit is contained in:
@@ -19,7 +19,9 @@ from app.services.sse_service import SSEService
|
||||
from app.services.notification_orchestrator import NotificationOrchestrator
|
||||
from app.services.email_service import EmailService
|
||||
from app.services.whatsapp_service import WhatsAppService
|
||||
from app.consumers.po_event_consumer import POEventConsumer
|
||||
from shared.service_base import StandardFastAPIService
|
||||
import asyncio
|
||||
|
||||
|
||||
class NotificationService(StandardFastAPIService):
|
||||
@@ -52,6 +54,8 @@ class NotificationService(StandardFastAPIService):
|
||||
self.orchestrator = None
|
||||
self.email_service = None
|
||||
self.whatsapp_service = None
|
||||
self.po_consumer = None
|
||||
self.po_consumer_task = None
|
||||
|
||||
# Define custom metrics for notification service
|
||||
notification_custom_metrics = {
|
||||
@@ -190,8 +194,32 @@ class NotificationService(StandardFastAPIService):
|
||||
app.state.email_service = self.email_service
|
||||
app.state.whatsapp_service = self.whatsapp_service
|
||||
|
||||
# Initialize and start PO event consumer
|
||||
self.po_consumer = POEventConsumer(self.email_service)
|
||||
|
||||
# Start consuming PO approved events in background
|
||||
# Use the global notification_publisher from messaging module
|
||||
from app.services.messaging import notification_publisher
|
||||
if notification_publisher and notification_publisher.connected:
|
||||
self.po_consumer_task = asyncio.create_task(
|
||||
self.po_consumer.consume_po_approved_event(notification_publisher)
|
||||
)
|
||||
self.logger.info("PO event consumer started successfully")
|
||||
else:
|
||||
self.logger.warning("RabbitMQ not connected, PO event consumer not started")
|
||||
|
||||
app.state.po_consumer = self.po_consumer
|
||||
|
||||
async def on_shutdown(self, app: FastAPI):
|
||||
"""Custom shutdown logic for notification service"""
|
||||
# Cancel PO consumer task
|
||||
if self.po_consumer_task and not self.po_consumer_task.done():
|
||||
self.po_consumer_task.cancel()
|
||||
try:
|
||||
await self.po_consumer_task
|
||||
except asyncio.CancelledError:
|
||||
self.logger.info("PO event consumer task cancelled")
|
||||
|
||||
# Shutdown SSE service
|
||||
if self.sse_service:
|
||||
await self.sse_service.shutdown()
|
||||
|
||||
Reference in New Issue
Block a user