@@ -995,35 +995,67 @@ def execution_section(self, start_workflow_function) -> None:
995995 log_level = c1 .selectbox (
996996 "log details" , ["minimal" , "commands and run times" , "all" ], key = "log_level"
997997 )
998- if self .executor .pid_dir .exists ():
998+
999+ # Real-time display options
1000+ if "log_lines_count" not in st .session_state :
1001+ st .session_state .log_lines_count = 100
1002+
1003+ log_lines_count = c2 .selectbox (
1004+ "lines to show" , [50 , 100 , 200 , 500 , "all" ],
1005+ index = 1 , key = "log_lines_select"
1006+ )
1007+ if log_lines_count != "all" :
1008+ st .session_state .log_lines_count = log_lines_count
1009+
1010+ pid_exists = self .executor .pid_dir .exists ()
1011+ log_path = Path (self .workflow_dir , "logs" , log_level .replace (" " , "-" ) + ".log" )
1012+ log_exists = log_path .exists ()
1013+
1014+ if pid_exists :
9991015 if c1 .button ("Stop Workflow" , type = "primary" , use_container_width = True ):
10001016 self .executor .stop ()
10011017 st .rerun ()
10021018 elif c1 .button ("Start Workflow" , type = "primary" , use_container_width = True ):
10031019 start_workflow_function ()
1004- st .rerun ()
1005- log_path = Path (self .workflow_dir , "logs" , log_level .replace (" " , "-" ) + ".log" )
1006- if log_path .exists ():
1007- if self .executor .pid_dir .exists ():
1008- with st .spinner ("**Workflow running...**" ):
1009- with open (log_path , "r" , encoding = "utf-8" ) as f :
1010- st .code (
1011- "" .join (f .readlines ()[- 30 :]),
1012- language = "neon" ,
1013- line_numbers = False ,
1014- )
1015- time .sleep (2 )
1020+ with st .spinner ("**Workflow running...**" ):
1021+ time .sleep (1 )
10161022 st .rerun ()
1017- else :
1018- st . markdown (
1019- f"**Workflow log file: { datetime . fromtimestamp ( log_path . stat (). st_ctime ). strftime ( '%Y-%m-%d %H:%M' ) } CET**"
1020- )
1023+
1024+ if log_exists and pid_exists :
1025+ # Real-time display during execution
1026+ with st . spinner ( "**Workflow running...**" ):
10211027 with open (log_path , "r" , encoding = "utf-8" ) as f :
1022- content = f .read ()
1023- # Check if workflow finished successfully
1024- if not "WORKFLOW FINISHED" in content :
1025- st .error ("**Errors occurred, check log file.**" )
1026- st .code (content , language = "neon" , line_numbers = False )
1028+ lines = f .readlines ()
1029+ if log_lines_count == "all" :
1030+ display_lines = lines
1031+ else :
1032+ display_lines = lines [- st .session_state .log_lines_count :]
1033+ st .code (
1034+ "" .join (display_lines ),
1035+ language = "neon" ,
1036+ line_numbers = False ,
1037+ )
1038+ # Faster polling for real-time updates
1039+ time .sleep (1 )
1040+ st .rerun ()
1041+
1042+ elif log_exists and not pid_exists :
1043+ # Static display after completion
1044+ st .markdown (
1045+ f"**Workflow log file: { datetime .fromtimestamp (log_path .stat ().st_ctime ).strftime ('%Y-%m-%d %H:%M' )} CET**"
1046+ )
1047+ with open (log_path , "r" , encoding = "utf-8" ) as f :
1048+ content = f .read ()
1049+ # Check if workflow finished successfully
1050+ if not "WORKFLOW FINISHED" in content :
1051+ st .error ("**Errors occurred, check log file.**" )
1052+ st .code (content , language = "neon" , line_numbers = False )
1053+ elif pid_exists :
1054+ with st .spinner ("**Workflow running...**" ):
1055+ time .sleep (1 )
1056+ st .rerun ()
1057+
1058+
10271059
10281060 def results_section (self , custom_results_function ) -> None :
10291061 custom_results_function ()
0 commit comments