4444CONTAINERS_API_URL = f'https://containers.datacrunch.io/{ DEPLOYMENT_NAME } '
4545
4646# DataCrunch client instance (global for graceful shutdown)
47- datacrunch = None
47+ datacrunch_client = None
4848
4949
5050def wait_for_deployment_health (client : DataCrunchClient , deployment_name : str , max_attempts : int = 20 , delay : int = 30 ) -> bool :
@@ -92,7 +92,7 @@ def graceful_shutdown(signum, frame) -> None:
9292 """Handle graceful shutdown on signals."""
9393 print (f"\n Signal { signum } received, cleaning up resources..." )
9494 try :
95- cleanup_resources (datacrunch )
95+ cleanup_resources (datacrunch_client )
9696 except Exception as e :
9797 print (f"Error during cleanup: { e } " )
9898 sys .exit (0 )
@@ -176,8 +176,8 @@ def main() -> None:
176176 return
177177
178178 # Initialize client
179- global datacrunch
180- datacrunch = DataCrunchClient (
179+ global datacrunch_client
180+ datacrunch_client = DataCrunchClient (
181181 DATACRUNCH_CLIENT_ID , DATACRUNCH_CLIENT_SECRET )
182182
183183 # Register signal handlers for cleanup
@@ -188,12 +188,12 @@ def main() -> None:
188188 print (f"Creating secret for Hugging Face token: { HF_SECRET_NAME } " )
189189 try :
190190 # Check if secret already exists
191- existing_secrets = datacrunch .containers .get_secrets ()
191+ existing_secrets = datacrunch_client .containers .get_secrets ()
192192 secret_exists = any (
193193 secret .name == HF_SECRET_NAME for secret in existing_secrets )
194194
195195 if not secret_exists :
196- datacrunch .containers .create_secret (
196+ datacrunch_client .containers .create_secret (
197197 HF_SECRET_NAME , HF_TOKEN )
198198 print (f"Secret '{ HF_SECRET_NAME } ' created successfully" )
199199 else :
@@ -264,14 +264,14 @@ def main() -> None:
264264 )
265265
266266 # Create the deployment
267- created_deployment = datacrunch .containers .create (deployment )
267+ created_deployment = datacrunch_client .containers .create (deployment )
268268 print (f"Created deployment: { created_deployment .name } " )
269269 print ("This will take several minutes while the model is downloaded and the server starts..." )
270270
271271 # Wait for deployment to be healthy
272- if not wait_for_deployment_health (datacrunch , DEPLOYMENT_NAME ):
272+ if not wait_for_deployment_health (datacrunch_client , DEPLOYMENT_NAME ):
273273 print ("Deployment health check failed" )
274- cleanup_resources (datacrunch )
274+ cleanup_resources (datacrunch_client )
275275 return
276276
277277 # Get the deployment endpoint URL and inference API key
@@ -301,7 +301,7 @@ def main() -> None:
301301 keep_running = input (
302302 "\n Do you want to keep the deployment running? (y/n): " )
303303 if keep_running .lower () != 'y' :
304- cleanup_resources (datacrunch )
304+ cleanup_resources (datacrunch_client )
305305 else :
306306 print (
307307 f"Deployment { DEPLOYMENT_NAME } is running. Don't forget to delete it when finished." )
@@ -312,7 +312,7 @@ def main() -> None:
312312 print (f"Unexpected error: { e } " )
313313 # Attempt cleanup even if there was an error
314314 try :
315- cleanup_resources (datacrunch )
315+ cleanup_resources (datacrunch_client )
316316 except Exception as cleanup_error :
317317 print (f"Error during cleanup after failure: { cleanup_error } " )
318318
0 commit comments