refactor valkey into objects with health check
This commit is contained in:
@@ -8,6 +8,9 @@ from datetime import datetime
|
||||
import valkey
|
||||
from dotenv import load_dotenv
|
||||
import modules.utils as utils
|
||||
import modules.structs as structs
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
'''
|
||||
TO DO:
|
||||
@@ -18,15 +21,24 @@ TO DO:
|
||||
VK_IN: str = 'fr_orchestrator_input'
|
||||
VK_OUT: str = 'fr_orchestrator_output'
|
||||
|
||||
CONFIG_FILEPATH: str = '/algo_local_drive/algo_config.json'
|
||||
# CONFIG_FILEPATH: str = 'algo_config.json'
|
||||
|
||||
### Logging ###
|
||||
load_dotenv()
|
||||
LOG_FILEPATH: str = f'{os.getenv("LOGS_PATH")}/Fund_Rate_Algo_Orchestrator.log'
|
||||
|
||||
async def main() -> None:
|
||||
VAL_KEY: valkey.Valkey = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True)
|
||||
CONFIG_FILEPATH: str = '/algo_local_drive/algo_config.json'
|
||||
if not Path(CONFIG_FILEPATH).exists():
|
||||
CONFIG_FILEPATH: str = 'algo_config.json'
|
||||
|
||||
# Init Load Config File
|
||||
with open(file=CONFIG_FILEPATH, mode='r', encoding='utf-8') as f:
|
||||
Algo_Config: dict = json.load(fp=f)
|
||||
Algo_Config['Updated_Timestamp'] = round(number=datetime.now().timestamp()*1000)
|
||||
|
||||
# vk = structs.VK_Obj(vk_name = 'fr_orchestrator_output', data=Algo_Config)
|
||||
vk = structs.VK_Orchestrator_Out()
|
||||
await vk.set(VK_CON=VAL_KEY)
|
||||
|
||||
try:
|
||||
VK_PUBSUB: valkey.client.PubSub = VAL_KEY.pubsub()
|
||||
@@ -46,11 +58,16 @@ async def main() -> None:
|
||||
Algo_Config: dict = json.load(fp=f)
|
||||
Algo_Config['Updated_Timestamp'] = timestamp
|
||||
|
||||
if not Algo_Config:
|
||||
raise ValueError(f'Algo Orchestrator, config is none: {Algo_Config}')
|
||||
|
||||
# Update Config w Update Data
|
||||
Algo_Config: dict = utils.rec_set_dict(orig_dict=Algo_Config, new_dict=data)
|
||||
# Set VK KV w Updated Config
|
||||
VAL_KEY.set(name=VK_OUT, value=json.dumps(obj=Algo_Config))
|
||||
|
||||
# vk = structs.VK_Obj(vk_name = 'fr_orchestrator_output', data=Algo_Config)
|
||||
vk = structs.VK_Orchestrator_Out()
|
||||
await vk.set(VK_CON=VAL_KEY)
|
||||
|
||||
# Save Updated Config to File
|
||||
with open(file=CONFIG_FILEPATH, mode='w', encoding='utf-8') as f:
|
||||
|
||||
Reference in New Issue
Block a user