74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""ACB Processor Service - Prefect Managed"""
|
||
|
|
import subprocess
|
||
|
|
import sys
|
||
|
|
import time
|
||
|
|
from prefect import flow, task, get_run_logger
|
||
|
|
|
||
|
|
SERVICE_SCRIPT = "/mnt/dolphinng5_predict/prod/acb_processor_service.py"
|
||
|
|
|
||
|
|
@task
|
||
|
|
def check_acb() -> bool:
|
||
|
|
"""Check if ACB data is fresh in Hz."""
|
||
|
|
try:
|
||
|
|
import hazelcast
|
||
|
|
import json
|
||
|
|
from datetime import datetime, timezone
|
||
|
|
|
||
|
|
client = hazelcast.HazelcastClient(
|
||
|
|
cluster_name="dolphin",
|
||
|
|
cluster_members=["127.0.0.1:5701"],
|
||
|
|
)
|
||
|
|
features = client.get_map('DOLPHIN_FEATURES').blocking()
|
||
|
|
data = features.get('acb_boost')
|
||
|
|
client.shutdown()
|
||
|
|
|
||
|
|
if data:
|
||
|
|
print("ACB data present")
|
||
|
|
return True
|
||
|
|
return False
|
||
|
|
except Exception as e:
|
||
|
|
print(f"ACB check error: {e}")
|
||
|
|
return False
|
||
|
|
|
||
|
|
@flow(name="acb-processor-service")
|
||
|
|
def acb_service_flow():
|
||
|
|
"""Manage ACB Processor Service."""
|
||
|
|
logger = get_run_logger()
|
||
|
|
logger.info("Starting ACB Processor Service...")
|
||
|
|
|
||
|
|
# Start service
|
||
|
|
proc = subprocess.Popen(
|
||
|
|
[sys.executable, SERVICE_SCRIPT],
|
||
|
|
stdout=subprocess.PIPE,
|
||
|
|
stderr=subprocess.STDOUT,
|
||
|
|
universal_newlines=True
|
||
|
|
)
|
||
|
|
|
||
|
|
logger.info(f"ACB Service started (PID: {proc.pid})")
|
||
|
|
|
||
|
|
try:
|
||
|
|
while True:
|
||
|
|
time.sleep(60) # Check every minute
|
||
|
|
if proc.poll() is not None:
|
||
|
|
logger.error("ACB Service died, restarting...")
|
||
|
|
proc = subprocess.Popen(
|
||
|
|
[sys.executable, SERVICE_SCRIPT],
|
||
|
|
stdout=subprocess.PIPE,
|
||
|
|
stderr=subprocess.STDOUT,
|
||
|
|
universal_newlines=True
|
||
|
|
)
|
||
|
|
else:
|
||
|
|
healthy = check_acb()
|
||
|
|
if healthy:
|
||
|
|
logger.info("✅ ACB healthy")
|
||
|
|
else:
|
||
|
|
logger.warning("⚠️ ACB data not in Hz yet")
|
||
|
|
except KeyboardInterrupt:
|
||
|
|
logger.info("Stopping ACB Service...")
|
||
|
|
proc.terminate()
|
||
|
|
proc.wait()
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
acb_service_flow()
|