#!/usr/bin/env python3 """ ExF System Deployment Setup ============================ Creates Prefect deployment for the ExF fetcher flow. Uses Prefect 3.x syntax with long-running process pattern. """ import sys import asyncio from pathlib import Path # Add paths sys.path.insert(0, str(Path(__file__).parent.parent)) sys.path.insert(0, str(Path(__file__).parent.parent / "external_factors")) from prefect import serve, get_client from prod.exf_fetcher_flow import exf_fetcher_flow async def setup_deployment(): """Set up ExF deployment for unattended operation.""" print("=" * 60) print("ExF Deployment Setup") print("=" * 60) # Check existing deployments async with get_client() as client: deployments = await client.read_deployments() exf_deployments = [d for d in deployments if 'exf' in d.name.lower()] print(f"\nFound {len(exf_deployments)} existing ExF deployments:") for d in exf_deployments: print(f" - {d.name} (ID: {d.id})") # Clean up old ExF deployments to avoid conflicts for d in exf_deployments: print(f" Deleting old deployment: {d.name}") try: await client.delete_deployment(d.id) print(f" ✓ Deleted") except Exception as e: print(f" ✗ Error: {e}") print("\n" + "=" * 60) print("Serving ExF Flow") print("=" * 60) print("\nThe ExF flow is a LONG-RUNNING daemon, not a scheduled job.") print("It will:") print(" - Poll indicators continuously at 0.5s intervals") print(" - Push to Hazelcast every 0.5s") print(" - Run until manually stopped") print("\nTo start manually:") print(" cd /mnt/dolphinng5_predict/prod") print(" python exf_fetcher_flow.py") print("\nTo run as background service:") print(" nohup python exf_fetcher_flow.py > /var/log/exf.log 2>&1 &") # Note: We don't use serve() for long-running daemons # serve() is for scheduled flows. Instead, we document how to run it. print("\n" + "=" * 60) print("Setup Complete") print("=" * 60) if __name__ == "__main__": asyncio.run(setup_deployment())