Kshitijk20 commited on
Commit
7f4cb77
·
1 Parent(s): 80743f2

refactor training route to log flow state and raise errors instead of fallback on failure

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -81,18 +81,21 @@ async def training_route():
81
  logging.info("Triggering training via Prefect Cloud...")
82
  import sys
83
  sys.path.append('/app')
 
 
84
  from prefect_flows.training_flow import training_flow
85
 
86
- # Run the flow synchronously
87
- result = training_flow()
88
- logging.info(f"Training flow completed: {result}")
89
 
90
- return Response(f"✅ Training completed via Prefect Cloud!\n\nCheck dashboard: https://app.prefect.cloud/account/{os.getenv('PREFECT_WORKSPACE', 'kshitij/default')}/flow-runs")
91
  except Exception as prefect_error:
92
  logging.error(f"Prefect training failed: {str(prefect_error)}", exc_info=True)
93
- return Response(f"❌ Prefect training failed: {str(prefect_error)}\n\nFalling back to direct training...")
 
94
 
95
- # Fallback: Direct training (only if Prefect not enabled)
96
  logging.info("Running direct training (Prefect not enabled)")
97
  training_pipeline = Trainingpipeline()
98
  training_pipeline.run_pipeline()
 
81
  logging.info("Triggering training via Prefect Cloud...")
82
  import sys
83
  sys.path.append('/app')
84
+
85
+ # Import and run flow directly (will auto-sync to Prefect Cloud)
86
  from prefect_flows.training_flow import training_flow
87
 
88
+ # Run the flow - it will automatically log to Prefect Cloud
89
+ flow_state = training_flow()
90
+ logging.info(f"Training flow completed with state: {flow_state}")
91
 
92
+ return Response(f"✅ Training completed via Prefect Cloud!\n\nCheck dashboard: https://app.prefect.cloud/\n\nFlow State: {flow_state}")
93
  except Exception as prefect_error:
94
  logging.error(f"Prefect training failed: {str(prefect_error)}", exc_info=True)
95
+ # Don't fallback - show the error
96
+ raise NetworkSecurityException(prefect_error, sys)
97
 
98
+ # Direct training if Prefect not enabled
99
  logging.info("Running direct training (Prefect not enabled)")
100
  training_pipeline = Trainingpipeline()
101
  training_pipeline.run_pipeline()