refactor: remove all postgresql related
Some checks failed
Build Worker Base and Application Images / check-base-changes (push) Successful in 7s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 2m38s
Build Worker Base and Application Images / deploy-stack (push) Failing after 16s
Some checks failed
Build Worker Base and Application Images / check-base-changes (push) Successful in 7s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 2m38s
Build Worker Base and Application Images / deploy-stack (push) Failing after 16s
This commit is contained in:
parent
d1276885c0
commit
eb9bedae67
6 changed files with 545 additions and 497 deletions
|
|
@ -15,7 +15,7 @@ from ..models.inference import YOLOWrapper
|
|||
from ..models.pipeline import PipelineParser
|
||||
from .branches import BranchProcessor
|
||||
from ..storage.redis import RedisManager
|
||||
from ..storage.database import DatabaseManager
|
||||
# from ..storage.database import DatabaseManager # Disabled - PostgreSQL moved to microservices
|
||||
from ..storage.license_plate import LicensePlateManager
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -45,7 +45,7 @@ class DetectionPipeline:
|
|||
# Initialize components
|
||||
self.branch_processor = BranchProcessor(model_manager, model_id)
|
||||
self.redis_manager = None
|
||||
self.db_manager = None
|
||||
# self.db_manager = None # Disabled - PostgreSQL operations moved to microservices
|
||||
self.license_plate_manager = None
|
||||
|
||||
# Main detection model
|
||||
|
|
@ -113,16 +113,18 @@ class DetectionPipeline:
|
|||
return False
|
||||
logger.info("Redis connection initialized")
|
||||
|
||||
# Initialize database connection
|
||||
if self.pipeline_parser.postgresql_config:
|
||||
self.db_manager = DatabaseManager(self.pipeline_parser.postgresql_config.__dict__)
|
||||
if not self.db_manager.connect():
|
||||
logger.error("Failed to initialize database connection")
|
||||
return False
|
||||
# Create required tables
|
||||
if not self.db_manager.create_car_frontal_info_table():
|
||||
logger.warning("Failed to create car_frontal_info table")
|
||||
logger.info("Database connection initialized")
|
||||
# PostgreSQL database connection DISABLED - operations moved to microservices
|
||||
# Database operations are now handled by backend services via WebSocket
|
||||
# if self.pipeline_parser.postgresql_config:
|
||||
# self.db_manager = DatabaseManager(self.pipeline_parser.postgresql_config.__dict__)
|
||||
# if not self.db_manager.connect():
|
||||
# logger.error("Failed to initialize database connection")
|
||||
# return False
|
||||
# # Create required tables
|
||||
# if not self.db_manager.create_car_frontal_info_table():
|
||||
# logger.warning("Failed to create car_frontal_info table")
|
||||
# logger.info("Database connection initialized")
|
||||
logger.info("PostgreSQL operations disabled - using WebSocket for data communication")
|
||||
|
||||
# Initialize license plate manager (using same Redis config as main Redis manager)
|
||||
if self.pipeline_parser.redis_config:
|
||||
|
|
@ -138,11 +140,11 @@ class DetectionPipeline:
|
|||
logger.error("Failed to initialize detection model")
|
||||
return False
|
||||
|
||||
# Initialize branch processor
|
||||
# Initialize branch processor (db_manager=None since PostgreSQL is disabled)
|
||||
if not await self.branch_processor.initialize(
|
||||
self.pipeline_config,
|
||||
self.redis_manager,
|
||||
self.db_manager
|
||||
db_manager=None # PostgreSQL disabled
|
||||
):
|
||||
logger.error("Failed to initialize branch processor")
|
||||
return False
|
||||
|
|
@ -283,23 +285,25 @@ class DetectionPipeline:
|
|||
return
|
||||
|
||||
# Send imageDetection message with license plate data combined with processing results
|
||||
# This is the PRIMARY data flow to backend - WebSocket is critical, keep this!
|
||||
await self._send_license_plate_message(subscription_id, license_text, confidence, session_id)
|
||||
|
||||
# Update database with license plate information if database manager is available
|
||||
if self.db_manager and license_text:
|
||||
success = self.db_manager.execute_update(
|
||||
table='car_frontal_info',
|
||||
key_field='session_id',
|
||||
key_value=session_id,
|
||||
fields={
|
||||
'license_character': license_text,
|
||||
'license_type': 'LPR_detected' # Mark as detected by LPR service
|
||||
}
|
||||
)
|
||||
if success:
|
||||
logger.info(f"[LICENSE PLATE] Updated database for session {session_id}")
|
||||
else:
|
||||
logger.warning(f"[LICENSE PLATE] Failed to update database for session {session_id}")
|
||||
# PostgreSQL database update DISABLED - backend handles data via WebSocket messages
|
||||
# if self.db_manager and license_text:
|
||||
# success = self.db_manager.execute_update(
|
||||
# table='car_frontal_info',
|
||||
# key_field='session_id',
|
||||
# key_value=session_id,
|
||||
# fields={
|
||||
# 'license_character': license_text,
|
||||
# 'license_type': 'LPR_detected' # Mark as detected by LPR service
|
||||
# }
|
||||
# )
|
||||
# if success:
|
||||
# logger.info(f"[LICENSE PLATE] Updated database for session {session_id}")
|
||||
# else:
|
||||
# logger.warning(f"[LICENSE PLATE] Failed to update database for session {session_id}")
|
||||
logger.debug(f"[LICENSE PLATE] Data sent via WebSocket for session {session_id}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in license plate result callback: {e}", exc_info=True)
|
||||
|
|
@ -710,17 +714,18 @@ class DetectionPipeline:
|
|||
self.session_to_subscription[session_id] = subscription_id
|
||||
logger.info(f"[SESSION MAPPING] Stored mapping: sessionId '{session_id}' -> subscriptionIdentifier '{subscription_id}'")
|
||||
|
||||
# Initialize database record with session_id
|
||||
if session_id and self.db_manager:
|
||||
success = self.db_manager.insert_initial_detection(
|
||||
display_id=display_id,
|
||||
captured_timestamp=detection_context['timestamp'],
|
||||
session_id=session_id
|
||||
)
|
||||
if success:
|
||||
logger.info(f"Created initial database record with session {session_id}")
|
||||
else:
|
||||
logger.warning(f"Failed to create initial database record for session {session_id}")
|
||||
# PostgreSQL database insert DISABLED - backend handles data via WebSocket
|
||||
# if session_id and self.db_manager:
|
||||
# success = self.db_manager.insert_initial_detection(
|
||||
# display_id=display_id,
|
||||
# captured_timestamp=detection_context['timestamp'],
|
||||
# session_id=session_id
|
||||
# )
|
||||
# if success:
|
||||
# logger.info(f"Created initial database record with session {session_id}")
|
||||
# else:
|
||||
# logger.warning(f"Failed to create initial database record for session {session_id}")
|
||||
logger.debug(f"Session {session_id} will be communicated via WebSocket")
|
||||
|
||||
# Execute branches in parallel
|
||||
if hasattr(self.pipeline_config, 'branches') and self.pipeline_config.branches:
|
||||
|
|
@ -886,15 +891,16 @@ class DetectionPipeline:
|
|||
if valid_detections:
|
||||
logger.info(f"Found {len(valid_detections)} valid detections for pipeline processing")
|
||||
|
||||
# Initialize database record if session_id is provided
|
||||
if session_id and self.db_manager:
|
||||
success = self.db_manager.insert_initial_detection(
|
||||
display_id=display_id,
|
||||
captured_timestamp=detection_context['timestamp'],
|
||||
session_id=session_id
|
||||
)
|
||||
if not success:
|
||||
logger.warning(f"Failed to create initial database record for session {session_id}")
|
||||
# PostgreSQL database insert DISABLED - backend handles data via WebSocket
|
||||
# if session_id and self.db_manager:
|
||||
# success = self.db_manager.insert_initial_detection(
|
||||
# display_id=display_id,
|
||||
# captured_timestamp=detection_context['timestamp'],
|
||||
# session_id=session_id
|
||||
# )
|
||||
# if not success:
|
||||
# logger.warning(f"Failed to create initial database record for session {session_id}")
|
||||
logger.debug(f"Detection results for session {session_id} will be sent via WebSocket")
|
||||
|
||||
# Execute branches in parallel
|
||||
if hasattr(self.pipeline_config, 'branches') and self.pipeline_config.branches:
|
||||
|
|
@ -1025,11 +1031,16 @@ class DetectionPipeline:
|
|||
logger.debug(f"Executing parallel action: {action_type}")
|
||||
|
||||
if action_type == 'postgresql_update_combined':
|
||||
result = await self._execute_postgresql_update_combined(action, context)
|
||||
# PostgreSQL action SKIPPED - database operations disabled
|
||||
logger.info(f"Skipping PostgreSQL action '{action_type}' (disabled)")
|
||||
result = {'status': 'skipped', 'message': 'PostgreSQL operations disabled'}
|
||||
|
||||
# Update session state with processing results after database update
|
||||
if result.get('status') == 'success':
|
||||
await self._update_session_with_processing_results(context)
|
||||
# Still update session state for WebSocket messaging
|
||||
await self._update_session_with_processing_results(context)
|
||||
|
||||
# result = await self._execute_postgresql_update_combined(action, context)
|
||||
# if result.get('status') == 'success':
|
||||
# await self._update_session_with_processing_results(context)
|
||||
else:
|
||||
logger.warning(f"Unknown parallel action type: {action_type}")
|
||||
result = {'status': 'error', 'message': f'Unknown action type: {action_type}'}
|
||||
|
|
@ -1132,59 +1143,61 @@ class DetectionPipeline:
|
|||
logger.error(f"Error in redis_publish action: {e}", exc_info=True)
|
||||
return {'status': 'error', 'message': str(e)}
|
||||
|
||||
async def _execute_postgresql_update_combined(self,
|
||||
action: Dict,
|
||||
context: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Execute postgresql_update_combined action."""
|
||||
if not self.db_manager:
|
||||
return {'status': 'error', 'message': 'Database not available'}
|
||||
|
||||
try:
|
||||
# Wait for required branches if specified
|
||||
wait_for_branches = action.params.get('waitForBranches', [])
|
||||
branch_results = context.get('branch_results', {})
|
||||
|
||||
# Log missing branches but don't block the update (allow partial results)
|
||||
missing_branches = [b for b in wait_for_branches if b not in branch_results]
|
||||
if missing_branches:
|
||||
logger.warning(f"Some branches missing from results (will use null): {missing_branches}")
|
||||
available_branches = [b for b in wait_for_branches if b in branch_results]
|
||||
if available_branches:
|
||||
logger.info(f"Available branches for database update: {available_branches}")
|
||||
|
||||
# Prepare fields for database update
|
||||
table = action.params.get('table', 'car_frontal_info')
|
||||
key_field = action.params.get('key_field', 'session_id')
|
||||
key_value = action.params.get('key_value', '{session_id}').format(**context)
|
||||
field_mappings = action.params.get('fields', {})
|
||||
|
||||
# Resolve field values using branch results
|
||||
resolved_fields = {}
|
||||
for field_name, field_template in field_mappings.items():
|
||||
try:
|
||||
# Replace template variables with actual values from branch results
|
||||
resolved_value = self._resolve_field_template(field_template, branch_results, context)
|
||||
resolved_fields[field_name] = resolved_value
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to resolve field {field_name}: {e}")
|
||||
resolved_fields[field_name] = None
|
||||
|
||||
# Execute database update
|
||||
success = self.db_manager.execute_update(
|
||||
table=table,
|
||||
key_field=key_field,
|
||||
key_value=key_value,
|
||||
fields=resolved_fields
|
||||
)
|
||||
|
||||
if success:
|
||||
return {'status': 'success', 'table': table, 'key': f'{key_field}={key_value}', 'fields': resolved_fields}
|
||||
else:
|
||||
return {'status': 'error', 'message': 'Database update failed'}
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in postgresql_update_combined action: {e}", exc_info=True)
|
||||
return {'status': 'error', 'message': str(e)}
|
||||
# PostgreSQL update method DISABLED - database operations moved to microservices
|
||||
# This method is no longer used as data flows via WebSocket messages to backend
|
||||
# async def _execute_postgresql_update_combined(self,
|
||||
# action: Dict,
|
||||
# context: Dict[str, Any]) -> Dict[str, Any]:
|
||||
# """Execute postgresql_update_combined action."""
|
||||
# if not self.db_manager:
|
||||
# return {'status': 'error', 'message': 'Database not available'}
|
||||
#
|
||||
# try:
|
||||
# # Wait for required branches if specified
|
||||
# wait_for_branches = action.params.get('waitForBranches', [])
|
||||
# branch_results = context.get('branch_results', {})
|
||||
#
|
||||
# # Log missing branches but don't block the update (allow partial results)
|
||||
# missing_branches = [b for b in wait_for_branches if b not in branch_results]
|
||||
# if missing_branches:
|
||||
# logger.warning(f"Some branches missing from results (will use null): {missing_branches}")
|
||||
# available_branches = [b for b in wait_for_branches if b in branch_results]
|
||||
# if available_branches:
|
||||
# logger.info(f"Available branches for database update: {available_branches}")
|
||||
#
|
||||
# # Prepare fields for database update
|
||||
# table = action.params.get('table', 'car_frontal_info')
|
||||
# key_field = action.params.get('key_field', 'session_id')
|
||||
# key_value = action.params.get('key_value', '{session_id}').format(**context)
|
||||
# field_mappings = action.params.get('fields', {})
|
||||
#
|
||||
# # Resolve field values using branch results
|
||||
# resolved_fields = {}
|
||||
# for field_name, field_template in field_mappings.items():
|
||||
# try:
|
||||
# # Replace template variables with actual values from branch results
|
||||
# resolved_value = self._resolve_field_template(field_template, branch_results, context)
|
||||
# resolved_fields[field_name] = resolved_value
|
||||
# except Exception as e:
|
||||
# logger.warning(f"Failed to resolve field {field_name}: {e}")
|
||||
# resolved_fields[field_name] = None
|
||||
#
|
||||
# # Execute database update
|
||||
# success = self.db_manager.execute_update(
|
||||
# table=table,
|
||||
# key_field=key_field,
|
||||
# key_value=key_value,
|
||||
# fields=resolved_fields
|
||||
# )
|
||||
#
|
||||
# if success:
|
||||
# return {'status': 'success', 'table': table, 'key': f'{key_field}={key_value}', 'fields': resolved_fields}
|
||||
# else:
|
||||
# return {'status': 'error', 'message': 'Database update failed'}
|
||||
#
|
||||
# except Exception as e:
|
||||
# logger.error(f"Error in postgresql_update_combined action: {e}", exc_info=True)
|
||||
# return {'status': 'error', 'message': str(e)}
|
||||
|
||||
def _resolve_field_template(self, template: str, branch_results: Dict, context: Dict) -> str:
|
||||
"""
|
||||
|
|
@ -1270,7 +1283,7 @@ class DetectionPipeline:
|
|||
'branches': branch_stats,
|
||||
'license_plate': license_stats,
|
||||
'redis_available': self.redis_manager is not None,
|
||||
'database_available': self.db_manager is not None,
|
||||
# 'database_available': self.db_manager is not None, # PostgreSQL disabled
|
||||
'detection_model_loaded': self.detection_model is not None
|
||||
}
|
||||
|
||||
|
|
@ -1282,8 +1295,9 @@ class DetectionPipeline:
|
|||
if self.redis_manager:
|
||||
self.redis_manager.cleanup()
|
||||
|
||||
if self.db_manager:
|
||||
self.db_manager.disconnect()
|
||||
# PostgreSQL disconnect DISABLED - database operations moved to microservices
|
||||
# if self.db_manager:
|
||||
# self.db_manager.disconnect()
|
||||
|
||||
if self.branch_processor:
|
||||
self.branch_processor.cleanup()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue