Enhance OKXCollector with improved heartbeat and logging functionality
- Added logger parameter to the OKXCollector to enable detailed ping/pong logging. - Updated message processing methods to maintain heartbeat and track data reception timestamps. - Adjusted ProductionManager to disable auto-restart and enable full logging for debugging WebSocket issues. - Enhanced overall logging capabilities to facilitate better monitoring and troubleshooting of data collection processes.
This commit is contained in:
@@ -145,7 +145,8 @@ class OKXCollector(BaseDataCollector):
|
||||
ping_interval=25.0,
|
||||
pong_timeout=10.0,
|
||||
max_reconnect_attempts=5,
|
||||
reconnect_delay=5.0
|
||||
reconnect_delay=5.0,
|
||||
logger=self.logger # Pass the logger to enable ping/pong logging
|
||||
)
|
||||
|
||||
# Add message callback
|
||||
@@ -346,6 +347,16 @@ class OKXCollector(BaseDataCollector):
|
||||
"""Handle message processing in the background."""
|
||||
# The new data processor handles messages through callbacks
|
||||
# This method exists for compatibility with BaseDataCollector
|
||||
|
||||
# Update heartbeat to indicate the message loop is active
|
||||
self._last_heartbeat = datetime.now(timezone.utc)
|
||||
|
||||
# Check if we're receiving WebSocket messages
|
||||
if self._ws_client and self._ws_client.is_connected:
|
||||
# Update last data received timestamp if WebSocket is connected and active
|
||||
self._last_data_received = datetime.now(timezone.utc)
|
||||
|
||||
# Short sleep to prevent busy loop while maintaining heartbeat
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
async def _store_processed_data(self, data_point: MarketDataPoint) -> None:
|
||||
@@ -443,6 +454,12 @@ class OKXCollector(BaseDataCollector):
|
||||
message: WebSocket message from OKX
|
||||
"""
|
||||
try:
|
||||
# Update heartbeat and data received timestamps
|
||||
current_time = datetime.now(timezone.utc)
|
||||
self._last_heartbeat = current_time
|
||||
self._last_data_received = current_time
|
||||
self._message_count += 1
|
||||
|
||||
# Process message asynchronously
|
||||
asyncio.create_task(self._process_message(message))
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user