@@ -34,11 +34,8 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
3434
3535app = FastAPI (title = "DataGenFlow" , version = "0.1.0" , lifespan = lifespan )
3636
37- # api router
38- api = FastAPI ()
3937
40-
41- @api .post ("/generate_from_file" )
38+ @app .post ("/generate_from_file" )
4239async def generate_from_file (
4340 file : UploadFile = File (...), pipeline_id : int = Form (...)
4441) -> dict [str , Any ]:
@@ -89,7 +86,7 @@ async def generate_from_file(
8986 return {"total" : total , "success" : success , "failed" : failed }
9087
9188
92- @api .post ("/generate" )
89+ @app .post ("/generate" )
9390async def generate (file : UploadFile = File (...), pipeline_id : int = Form (...)) -> dict [str , Any ]:
9491 """start a new background job for pipeline execution from seed file"""
9592 if not file .filename or not file .filename .endswith (".json" ):
@@ -166,7 +163,7 @@ async def generate(file: UploadFile = File(...), pipeline_id: int = Form(...)) -
166163 return {"job_id" : job_id }
167164
168165
169- @api .get ("/jobs/active" )
166+ @app .get ("/jobs/active" )
170167async def get_active_job () -> dict [str , Any ] | None :
171168 """get currently running job"""
172169 active_job = job_queue .get_active_job ()
@@ -175,7 +172,7 @@ async def get_active_job() -> dict[str, Any] | None:
175172 return active_job
176173
177174
178- @api .get ("/jobs/{job_id}" )
175+ @app .get ("/jobs/{job_id}" )
179176async def get_job (job_id : int ) -> dict [str , Any ]:
180177 """get job status by id"""
181178 # try memory first
@@ -190,7 +187,7 @@ async def get_job(job_id: int) -> dict[str, Any]:
190187 return job
191188
192189
193- @api .delete ("/jobs/{job_id}" )
190+ @app .delete ("/jobs/{job_id}" )
194191async def cancel_job (job_id : int ) -> dict [str , str ]:
195192 """cancel a running job"""
196193 success = job_queue .cancel_job (job_id )
@@ -203,7 +200,7 @@ async def cancel_job(job_id: int) -> dict[str, str]:
203200 return {"message" : "Job cancelled" }
204201
205202
206- @api .get ("/jobs" )
203+ @app .get ("/jobs" )
207204async def list_jobs (pipeline_id : int | None = None ) -> list [dict [str , Any ]]:
208205 """list jobs, optionally filtered by pipeline_id"""
209206 # try memory first for recent jobs
@@ -216,7 +213,7 @@ async def list_jobs(pipeline_id: int | None = None) -> list[dict[str, Any]]:
216213 return await storage .list_jobs (pipeline_id = pipeline_id , limit = 10 )
217214
218215
219- @api .get ("/records" )
216+ @app .get ("/records" )
220217async def get_records (
221218 status : RecordStatus | None = None ,
222219 limit : int = 100 ,
@@ -230,15 +227,15 @@ async def get_records(
230227 return [record .model_dump () for record in records ]
231228
232229
233- @api .get ("/records/{record_id}" )
230+ @app .get ("/records/{record_id}" )
234231async def get_record (record_id : int ) -> dict [str , Any ]:
235232 record = await storage .get_by_id (record_id )
236233 if not record :
237234 raise HTTPException (status_code = 404 , detail = "record not found" )
238235 return record .model_dump ()
239236
240237
241- @api .put ("/records/{record_id}" )
238+ @app .put ("/records/{record_id}" )
242239async def update_record (record_id : int , update : RecordUpdate ) -> dict [str , bool ]:
243240 updates = update .model_dump (exclude_unset = True )
244241
@@ -260,7 +257,7 @@ async def update_record(record_id: int, update: RecordUpdate) -> dict[str, bool]
260257 return {"success" : True }
261258
262259
263- @api .delete ("/records" )
260+ @app .delete ("/records" )
264261async def delete_all_records (job_id : int | None = None ) -> dict [str , Any ]:
265262 count = await storage .delete_all_records (job_id = job_id )
266263 # also remove from in-memory job queue
@@ -269,15 +266,15 @@ async def delete_all_records(job_id: int | None = None) -> dict[str, Any]:
269266 return {"deleted" : count }
270267
271268
272- @api .get ("/export" )
269+ @app .get ("/export" )
273270async def export_records (
274271 status : RecordStatus | None = None , job_id : int | None = None
275272) -> PlainTextResponse :
276273 jsonl = await storage .export_jsonl (status = status , job_id = job_id )
277274 return PlainTextResponse (content = jsonl , media_type = "application/x-ndjson" )
278275
279276
280- @api .get ("/export/download" )
277+ @app .get ("/export/download" )
281278async def download_export (
282279 status : RecordStatus | None = None , job_id : int | None = None
283280) -> FileResponse :
@@ -291,12 +288,12 @@ async def download_export(
291288 )
292289
293290
294- @api .get ("/blocks" )
291+ @app .get ("/blocks" )
295292async def list_blocks () -> list [dict [str , Any ]]:
296293 return registry .list_blocks ()
297294
298295
299- @api .post ("/pipelines" )
296+ @app .post ("/pipelines" )
300297async def create_pipeline (pipeline_data : dict [str , Any ]) -> dict [str , Any ]:
301298 name = pipeline_data .get ("name" )
302299 blocks = pipeline_data .get ("blocks" )
@@ -308,20 +305,20 @@ async def create_pipeline(pipeline_data: dict[str, Any]) -> dict[str, Any]:
308305 return {"id" : pipeline_id , "name" : name }
309306
310307
311- @api .get ("/pipelines" )
308+ @app .get ("/pipelines" )
312309async def list_pipelines () -> list [dict [str , Any ]]:
313310 return await storage .list_pipelines ()
314311
315312
316- @api .get ("/pipelines/{pipeline_id}" )
313+ @app .get ("/pipelines/{pipeline_id}" )
317314async def get_pipeline (pipeline_id : int ) -> dict [str , Any ]:
318315 pipeline = await storage .get_pipeline (pipeline_id )
319316 if not pipeline :
320317 raise HTTPException (status_code = 404 , detail = "pipeline not found" )
321318 return pipeline
322319
323320
324- @api .put ("/pipelines/{pipeline_id}" )
321+ @app .put ("/pipelines/{pipeline_id}" )
325322async def update_pipeline (pipeline_id : int , pipeline_data : dict [str , Any ]) -> dict [str , Any ]:
326323 name = pipeline_data .get ("name" )
327324 blocks = pipeline_data .get ("blocks" )
@@ -336,7 +333,7 @@ async def update_pipeline(pipeline_id: int, pipeline_data: dict[str, Any]) -> di
336333 return {"id" : pipeline_id , "name" : name }
337334
338335
339- @api .post ("/pipelines/{pipeline_id}/execute" , response_model = None )
336+ @app .post ("/pipelines/{pipeline_id}/execute" , response_model = None )
340337async def execute_pipeline (pipeline_id : int , data : dict [str , Any ]) -> dict [str , Any ] | JSONResponse :
341338 try :
342339 pipeline_data = await storage .get_pipeline (pipeline_id )
@@ -360,7 +357,7 @@ async def execute_pipeline(pipeline_id: int, data: dict[str, Any]) -> dict[str,
360357 return JSONResponse (status_code = 500 , content = {"error" : f"Unexpected error: { str (e )} " })
361358
362359
363- @api .get ("/pipelines/{pipeline_id}/accumulated_state_schema" )
360+ @app .get ("/pipelines/{pipeline_id}/accumulated_state_schema" )
364361async def get_accumulated_state_schema (pipeline_id : int ) -> dict [str , list [str ]]:
365362 """get list of field names that will be in accumulated state for this pipeline"""
366363 pipeline_data = await storage .get_pipeline (pipeline_id )
@@ -372,7 +369,7 @@ async def get_accumulated_state_schema(pipeline_id: int) -> dict[str, list[str]]
372369 return {"fields" : fields }
373370
374371
375- @api .put ("/pipelines/{pipeline_id}/validation_config" )
372+ @app .put ("/pipelines/{pipeline_id}/validation_config" )
376373async def update_validation_config (
377374 pipeline_id : int , validation_config : dict [str , Any ]
378375) -> dict [str , bool ]:
@@ -402,7 +399,7 @@ async def update_validation_config(
402399 return {"success" : True }
403400
404401
405- @api .delete ("/pipelines/{pipeline_id}" )
402+ @app .delete ("/pipelines/{pipeline_id}" )
406403async def delete_pipeline (pipeline_id : int ) -> dict [str , bool ]:
407404 # get all jobs for this pipeline to remove from memory
408405 jobs = await storage .list_jobs (pipeline_id = pipeline_id , limit = 1000 )
@@ -419,13 +416,13 @@ async def delete_pipeline(pipeline_id: int) -> dict[str, bool]:
419416 return {"success" : True }
420417
421418
422- @api .get ("/templates" )
419+ @app .get ("/templates" )
423420async def list_templates () -> list [dict [str , Any ]]:
424421 """List all available pipeline templates"""
425422 return template_registry .list_templates ()
426423
427424
428- @api .post ("/pipelines/from_template/{template_id}" )
425+ @app .post ("/pipelines/from_template/{template_id}" )
429426async def create_pipeline_from_template (template_id : str ) -> dict [str , Any ]:
430427 """Create a new pipeline from a template"""
431428 template = template_registry .get_template (template_id )
@@ -441,7 +438,7 @@ async def create_pipeline_from_template(template_id: str) -> dict[str, Any]:
441438
442439
443440# mount api routes
444- app .mount ("/api" , api )
441+ app .mount ("/api" , app )
445442
446443# serve frontend (built react app)
447444frontend_dir = Path ("frontend/build" )
0 commit comments