Add POI feature and imporve the overall backend implementation

This commit is contained in:
Urtzi Alfaro
2025-11-12 15:34:10 +01:00
parent e8096cd979
commit 5783c7ed05
173 changed files with 16862 additions and 9078 deletions

View File

@@ -11,12 +11,13 @@ from sqlalchemy import text
from app.core.config import settings
from app.core.database import database_manager
from shared.service_base import StandardFastAPIService
from app.jobs.overdue_po_scheduler import OverduePOScheduler
class ProcurementService(StandardFastAPIService):
"""Procurement Service with standardized setup"""
expected_migration_version = "00001"
expected_migration_version = "001_unified_initial_schema"
async def verify_migrations(self):
"""Verify database schema matches the latest migrations"""
@@ -49,6 +50,10 @@ class ProcurementService(StandardFastAPIService):
'supplier_selection_history'
]
# Initialize scheduler and rabbitmq client
self.overdue_po_scheduler = None
self.rabbitmq_client = None
super().__init__(
service_name="procurement-service",
app_name=settings.APP_NAME,
@@ -56,18 +61,58 @@ class ProcurementService(StandardFastAPIService):
version=settings.VERSION,
api_prefix="", # Empty because RouteBuilder already includes /api/v1
database_manager=database_manager,
expected_tables=procurement_expected_tables
expected_tables=procurement_expected_tables,
enable_messaging=True # Enable RabbitMQ for event publishing
)
async def _setup_messaging(self):
"""Setup messaging for procurement service"""
from shared.messaging.rabbitmq import RabbitMQClient
try:
self.rabbitmq_client = RabbitMQClient(settings.RABBITMQ_URL, service_name="procurement-service")
await self.rabbitmq_client.connect()
self.logger.info("Procurement service messaging setup completed")
except Exception as e:
self.logger.error("Failed to setup procurement messaging", error=str(e))
raise
async def _cleanup_messaging(self):
"""Cleanup messaging for procurement service"""
try:
if self.rabbitmq_client:
await self.rabbitmq_client.disconnect()
self.logger.info("Procurement service messaging cleanup completed")
except Exception as e:
self.logger.error("Error during procurement messaging cleanup", error=str(e))
async def on_startup(self, app: FastAPI):
"""Custom startup logic for procurement service"""
await super().on_startup(app)
self.logger.info("Procurement Service starting up...")
# Future: Initialize any background services if needed
# Start overdue PO scheduler
if self.rabbitmq_client and self.rabbitmq_client.connected:
self.overdue_po_scheduler = OverduePOScheduler(
rabbitmq_client=self.rabbitmq_client,
check_interval_seconds=3600 # Check every hour
)
await self.overdue_po_scheduler.start()
self.logger.info("Overdue PO scheduler started")
else:
self.logger.warning("RabbitMQ not available, overdue PO scheduler not started")
async def on_shutdown(self, app: FastAPI):
"""Custom shutdown logic for procurement service"""
self.logger.info("Procurement Service shutting down...")
# Stop overdue PO scheduler
if self.overdue_po_scheduler:
await self.overdue_po_scheduler.stop()
self.logger.info("Overdue PO scheduler stopped")
await super().on_shutdown(app)
def get_service_features(self):
"""Return procurement-specific features"""
return [