SIENTIAPDE-988 Implement core functionality for OPC ingestor, including main execution flow, IngestorManager methods, and OPC server management. Add unit tests for IngestorManager and OPCManager.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
from typing import List
|
||||
from redis import Redis
|
||||
|
||||
|
||||
@@ -48,19 +49,19 @@ class ResourceManager:
|
||||
self.redis.set(
|
||||
f"heartbeat:ingestor:{self.pod_id}", 1, ex=self.heartbeat_ttl)
|
||||
|
||||
def lease_tag(self, tag_id: str) -> None:
|
||||
def lease_tag(self, tag_id: str) -> bool:
|
||||
"""
|
||||
Acquires a lease for a specific OPC tag by setting a key in Redis with a
|
||||
time-to-live (TTL). This ensures that the tag is associated with the
|
||||
current pod for a limited duration.
|
||||
Attempts to lease a tag by setting a key in Redis with a specified TTL (time-to-live).
|
||||
This method uses the Redis `SET` command with the `NX` option to ensure that the key
|
||||
is only set if it does not already exist. The key is set with an expiration time
|
||||
defined by `lease_ttl`.
|
||||
Args:
|
||||
tag_id (str): The unique identifier of the OPC tag to lease.
|
||||
Raises:
|
||||
redis.exceptions.RedisError: If there is an issue communicating with
|
||||
the Redis server.
|
||||
tag_id (str): The unique identifier of the tag to be leased.
|
||||
Returns:
|
||||
bool: True if the lease was successfully acquired, False otherwise.
|
||||
"""
|
||||
|
||||
self.redis.set(
|
||||
return self.redis.set(
|
||||
f"lease:opc_tags:{tag_id}", self.pod_id, nx=True, ex=self.lease_ttl)
|
||||
|
||||
def renew_tag_lease(self, tag_id: str) -> bool:
|
||||
@@ -82,3 +83,26 @@ class ResourceManager:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def drop_tag_lease(self, tag_id: str) -> None:
|
||||
"""
|
||||
Drops the lease for a specific OPC tag.
|
||||
This method removes the lease for the given OPC tag by deleting the corresponding key in Redis.
|
||||
Args:
|
||||
tag_id (str): The identifier of the OPC tag whose lease is to be dropped.
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
|
||||
self.redis.delete(f"lease:opc_tags:{tag_id}")
|
||||
|
||||
def get_all_ingestors(self) -> List[str]:
|
||||
"""
|
||||
Retrieves all active ingestors from Redis.
|
||||
This method fetches all keys in Redis that match the pattern for ingestor leases
|
||||
and returns a list of active ingestors.
|
||||
Returns:
|
||||
list: A list of active ingestors.
|
||||
"""
|
||||
|
||||
return self.redis.keys("heartbeat:ingestor:*")
|
||||
|
||||
Reference in New Issue
Block a user