fix: Improve Docker container shutdown handling
Local Docker Build (Dev) / build-dev (push) Successful in 3s
Local Docker Build (Dev) / build-dev (push) Successful in 3s
- Add proper signal handlers for graceful shutdown of all components - Implement WebhookBatcher.shutdown() to properly close ThreadPoolExecutor and cancel timers - Add NFOGuardDatabase.close() method to close thread-local database connections - Increase uvicorn graceful shutdown timeout to 15 seconds - Add cleanup in finally block to ensure resources are freed even if signal handler fails - Reduce logging and server header overhead for better performance This should resolve Docker container shutdown issues where containers don't respond to SIGTERM properly. Bump version to 2.1.1 🤖 Generated with [Claude Code](https://claude.ai/code)
This commit is contained in:
@@ -172,4 +172,33 @@ class WebhookBatcher:
|
||||
"processing_items": list(self.processing),
|
||||
"pending_count": len(self.pending),
|
||||
"processing_count": len(self.processing)
|
||||
}
|
||||
}
|
||||
|
||||
def shutdown(self):
|
||||
"""Shutdown the webhook batcher gracefully"""
|
||||
_log("INFO", "Shutting down webhook batcher...")
|
||||
|
||||
with self.lock:
|
||||
# Cancel all pending timers
|
||||
for timer in self.timers.values():
|
||||
try:
|
||||
timer.cancel()
|
||||
except Exception as e:
|
||||
_log("WARNING", f"Error canceling timer: {e}")
|
||||
|
||||
self.timers.clear()
|
||||
|
||||
# Log any remaining items
|
||||
if self.pending:
|
||||
_log("WARNING", f"Shutting down with {len(self.pending)} pending items")
|
||||
if self.processing:
|
||||
_log("INFO", f"Waiting for {len(self.processing)} items to finish processing...")
|
||||
|
||||
# Shutdown the thread pool executor
|
||||
try:
|
||||
self.executor.shutdown(wait=True, timeout=10) # Wait up to 10 seconds
|
||||
_log("INFO", "Thread pool executor shut down successfully")
|
||||
except Exception as e:
|
||||
_log("WARNING", f"Error shutting down thread pool: {e}")
|
||||
|
||||
_log("INFO", "Webhook batcher shutdown complete")
|
||||
Reference in New Issue
Block a user