@@ -328,14 +328,14 @@ def execute_workflow(self, repo_id, workflow_data, trigger_data):
328328 )
329329
330330 self ._record_workflow_run_start (context , graph_data )
331-
331+ start_time = time . time ()
332332 success = self ._execute_workflow_with_queue (context , graph )
333-
333+ elapsed_time = time . time () - start_time
334334 if success :
335- self ._update_workflow_run_status (context , COMPLETED )
335+ self ._update_workflow_run_status (context , COMPLETED , elapsed_time )
336336 logger .info (f"Workflow { context .workflow_id } executed successfully" )
337337 else :
338- self ._update_workflow_run_status (context , FAILED )
338+ self ._update_workflow_run_status (context , FAILED , elapsed_time )
339339 logger .error (f"Workflow { context .workflow_id } execution failed" )
340340
341341 return success
@@ -401,20 +401,17 @@ def _record_workflow_run_start(self, context, graph_data):
401401 try :
402402 sql = text ("""
403403 INSERT INTO workflow_run
404- (id, workflow_id, repo_id, graph, status, triggered_from , created_by, created_at, total_steps)
405- VALUES (:id, :workflow_id, :repo_id, :graph, : status, :triggered_from , :created_by, :created_at, :total_steps)
404+ (id, workflow_id, repo_id, status, created_by, created_at, total_steps)
405+ VALUES (:id, :workflow_id, :repo_id, :status, :created_by, :created_at, :total_steps)
406406 """ )
407407
408- graph_json = json .dumps (graph_data , ensure_ascii = False )
409408 total_steps = len (graph_data .get ('nodes' , []))
410409 record = context .trigger_data .get ('record' )
411410 self .db .execute (sql , {
412411 'id' : context .run_id ,
413412 'workflow_id' : context .workflow_id ,
414413 'repo_id' : context .repo_id ,
415- 'graph' : graph_json ,
416414 'status' : RUNNING ,
417- 'triggered_from' : 'file_upload' ,
418415 'created_by' : record .get ('op_user' ),
419416 'created_at' : datetime .now (),
420417 'total_steps' : total_steps
@@ -424,17 +421,18 @@ def _record_workflow_run_start(self, context, graph_data):
424421 except Exception as e :
425422 logger .error (f"Failed to record workflow run start: { str (e )} " )
426423
427- def _update_workflow_run_status (self , context , status ):
424+ def _update_workflow_run_status (self , context , status , elapsed_time ):
428425 try :
429426 sql = text ("""
430427 UPDATE workflow_run
431- SET status = :status, finished_at = :finished_at
428+ SET status = :status, finished_at = :finished_at, elapsed_time = :elapsed_time
432429 WHERE id = :id
433430 """ )
434431
435432 self .db .execute (sql , {
436433 'status' : status ,
437434 'finished_at' : datetime .now (),
435+ 'elapsed_time' : elapsed_time ,
438436 'id' : context .run_id
439437 })
440438 self .db .commit ()
0 commit comments