Update MongoDB connection handling in DataManager and enhance IngestorManager configuration
- Updated DataManager to simplify MongoDB connection logic by removing retry loop and adding logging for connection attempts. - Enhanced IngestorManager to accept MongoDB connection parameters and export_to_kafka flag as part of its initialization. - Updated requirements.txt to use the latest version of the sientia-dataops-library.
This commit is contained in:
@@ -75,26 +75,17 @@ class DataManager:
|
||||
logger.info(
|
||||
f"DataManager initialized with Kafka servers: {kafka_servers}")
|
||||
|
||||
logger.info(
|
||||
f"Trying to initializing DataManager with MongoDB servers: {mongo_connection_string}"
|
||||
)
|
||||
|
||||
self.connection_string = mongo_connection_string
|
||||
self.database = mongo_database
|
||||
|
||||
for i in range(0, 3):
|
||||
logger.info(
|
||||
f"Trying ({i}) to initializing DataManager with MongoDB servers: {self.connection_string}"
|
||||
)
|
||||
try:
|
||||
self.mongo_client = MongoClient(self.connection_string)
|
||||
self.mongo_client.server_info()
|
||||
self.mongo_client = MongoClient(self.connection_string)
|
||||
self.mongo_client.server_info()
|
||||
|
||||
self.mongo_db = self.mongo_client[self.database]
|
||||
break
|
||||
except Exception as e:
|
||||
logger.error(f"Error connecting to MongoDB: {e}")
|
||||
sleep(5)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Failed to connect to MongoDB servers {self.connection_string} after 3 attempts."
|
||||
)
|
||||
self.mongo_db = self.mongo_client[self.database]
|
||||
|
||||
logger.info(
|
||||
f"DataManager initialized with MongoDB servers: {self.connection_string}"
|
||||
@@ -123,6 +114,9 @@ class DataManager:
|
||||
self.mongo_client.close()
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error closing MongoDB client: {e}")
|
||||
else:
|
||||
self.logger.warning(
|
||||
"MongoDB client is already closed or not initialized.")
|
||||
|
||||
def __del__(self):
|
||||
self.shutdown()
|
||||
|
||||
@@ -162,7 +162,8 @@ class IngestorManager():
|
||||
_a = [self.managed_tags[slot].pop(server, None)
|
||||
for slot, _value in current_managed_tags.items()]
|
||||
|
||||
for server in self.opc_managers.keys():
|
||||
servers = list(self.opc_managers.keys())
|
||||
for server in servers:
|
||||
if server not in registered_servers:
|
||||
self.logger.warning(
|
||||
f"Server {server} not found in managed tags. "
|
||||
|
||||
Reference in New Issue
Block a user