File size: 5,084 Bytes
b5df735 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
"""
Simplified deployment manager
This replaces the complex deploy_endpoints.py with a cleaner interface
"""
import argparse
import sys
from typing import Optional
from ..audio_processing.deployment import ModalDeployer, EndpointManager
from ..audio_processing.utils.config import AudioProcessingConfig
from ..audio_processing.utils.errors import DeploymentError
class DeploymentManager:
"""Simplified deployment manager for audio processing services"""
def __init__(self):
self.config = AudioProcessingConfig()
self.modal_deployer = ModalDeployer(self.config)
self.endpoint_manager = EndpointManager()
def deploy(self) -> bool:
"""Deploy transcription service"""
try:
print("π Starting deployment process...")
endpoint_url = self.modal_deployer.deploy_transcription_service()
if endpoint_url:
print(f"β
Deployment successful!")
print(f"π Endpoint URL: {endpoint_url}")
return True
else:
print("β Deployment failed: Could not get endpoint URL")
return False
except DeploymentError as e:
print(f"β Deployment failed: {e.message}")
if e.details:
print(f"π Details: {e.details}")
return False
except Exception as e:
print(f"β Unexpected deployment error: {str(e)}")
return False
def status(self) -> bool:
"""Check deployment status"""
print("π Checking deployment status...")
endpoints = self.endpoint_manager.list_endpoints()
if not endpoints:
print("β No endpoints configured")
return False
print(f"π Configured endpoints:")
for name, url in endpoints.items():
print(f" β’ {name}: {url}")
# Check health
return self.modal_deployer.check_deployment_status()
def undeploy(self):
"""Remove deployment configuration"""
print("ποΈ Removing deployment configuration...")
self.modal_deployer.undeploy_transcription_service()
def list_endpoints(self):
"""List all configured endpoints"""
endpoints = self.endpoint_manager.list_endpoints()
if not endpoints:
print("π No endpoints configured")
return
print("π Configured endpoints:")
for name, url in endpoints.items():
health_status = "β
Healthy" if self.endpoint_manager.check_endpoint_health(name) else "β Unhealthy"
print(f" β’ {name}: {url} ({health_status})")
def set_endpoint(self, name: str, url: str):
"""Manually set an endpoint"""
self.endpoint_manager.set_endpoint(name, url)
def remove_endpoint(self, name: str):
"""Remove an endpoint"""
self.endpoint_manager.remove_endpoint(name)
def main():
"""Command line interface for deployment manager"""
parser = argparse.ArgumentParser(description="Audio Processing Deployment Manager")
subparsers = parser.add_subparsers(dest="command", help="Available commands")
# Deploy command
subparsers.add_parser("deploy", help="Deploy transcription service to Modal")
# Status command
subparsers.add_parser("status", help="Check deployment status")
# Undeploy command
subparsers.add_parser("undeploy", help="Remove deployment configuration")
# List endpoints command
subparsers.add_parser("list", help="List all configured endpoints")
# Set endpoint command
set_parser = subparsers.add_parser("set", help="Set endpoint URL manually")
set_parser.add_argument("name", help="Endpoint name")
set_parser.add_argument("url", help="Endpoint URL")
# Remove endpoint command
remove_parser = subparsers.add_parser("remove", help="Remove endpoint")
remove_parser.add_argument("name", help="Endpoint name")
args = parser.parse_args()
if not args.command:
parser.print_help()
return
manager = DeploymentManager()
try:
if args.command == "deploy":
success = manager.deploy()
sys.exit(0 if success else 1)
elif args.command == "status":
success = manager.status()
sys.exit(0 if success else 1)
elif args.command == "undeploy":
manager.undeploy()
elif args.command == "list":
manager.list_endpoints()
elif args.command == "set":
manager.set_endpoint(args.name, args.url)
elif args.command == "remove":
manager.remove_endpoint(args.name)
except KeyboardInterrupt:
print("\nβ οΈ Operation cancelled by user")
sys.exit(1)
except Exception as e:
print(f"β Error: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main() |