Message Processing
Thread Architecture
Main Thread
Receives message from RabbitMQ via
dashboard.notifications.common.runCalls
should_create_ticket(message)to validateIf valid: adds
retry_count=0and enqueues toqueue.QueueIf invalid: discards message
Processing Thread
For each message:
DB Check: Query
DashboardAlarmbyidIf not found → raise
TicketError(non-transient) → discard
TTS Check: Find overlapping maintenance tickets
If found → update existing ticket
If not found → create new ticket
DB Update: Set
DashboardAlarm.ticket_refto ticket numberError Handling:
TicketError→ log error, discard immediatelyOther exceptions → retry with exponential backoff
Retry Mechanism
Exponential Backoff:
delay = min(BASE_DELAY * (2^retry_count), MAX_DELAY)BASE_DELAY = 1.0secondMAX_DELAY = 60.0seconds
Max Retries:
MAX_RETRIES = 5Implementation: Uses
threading.Timerto re-queue after delayAfter Max Retries: Log error and discard message
Retry Schedule:
Retry |
Delay |
|---|---|
1 |
1s |
2 |
2s |
3 |
4s |
4 |
8s |
5 |
16s |
After 5 |
Discard |
Thread Safety
Queue:
queue.Queueis thread-safeTimers: Tracked in a lock-protected list
DB Session: Each message gets its own session via
session_scope()
Signal Handling
The service handles graceful shutdown on:
SIGTERM(standard termination)SIGINT(Ctrl+C)
Shutdown Behavior:
Set
stop_eventMain thread exits (RabbitMQ consumer stops)
Processing thread terminates (daemon thread)
Logging
Standard Python logging with format:
%(asctime)s - %(name)s - %(levelname)s - %(message)s
Log Levels
INFO: Service startup/shutdown, ticket creation/updates
WARNING: Transient errors with retry information
ERROR: TicketError, max retries exceeded
DEBUG: Message enqueue/dequeue, validation results
Example Logs
2026-04-02 10:15:30 - tts_api_notifier - INFO - Starting TTS API notifier service
2026-04-02 10:15:31 - tts_api_notifier - INFO - Processing thread started
2026-04-02 10:15:32 - tts_api_notifier - INFO - Created ticket TTS-12345 for alarm 67890
2026-04-02 10:16:05 - tts_api_notifier - WARNING - Error processing alarm 67891 (retry 1): Connection timeout
2026-04-02 10:16:05 - tts_api_notifier - WARNING - Scheduling retry 2 for alarm 67891 in 2.0s
Dependencies
dashboard.notifications.common- RabbitMQ integrationdashboard.correlation.db- Database accessclick- CLI frameworkPython standard library:
threading,queue,signal,logging,json