Skip to content

Commit f4afcf6

Browse files
committed
pipeline-runner: Option to cat failing logs to stdout
1 parent 3bca2cf commit f4afcf6

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

MC/bin/o2_dpg_workflow_runner.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ def monitor(self, process_list):
667667
def waitforany(self, process_list, finished):
668668
failuredetected = False
669669
failingpids = []
670+
failingtasks = []
670671
if len(process_list)==0:
671672
return False
672673

@@ -690,15 +691,32 @@ def waitforany(self, process_list, finished):
690691
if returncode!=0:
691692
failuredetected = True
692693
failingpids.append(pid)
694+
failingtasks.append(p[0])
693695

694696
if failuredetected and self.stoponfailure:
695697
actionlogger.info('Stoping pipeline due to failure in stages with PID ' + str(failingpids))
696698
# self.analyse_files_and_connections()
699+
self.cat_logfiles_tostdout(failingtasks)
700+
697701
self.stop_pipeline_and_exit(process_list)
698702

699703
# empty finished means we have to wait more
700704
return len(finished)==0
701705

706+
def cat_logfiles_tostdout(self, taskids):
707+
# In case of errors we can cat the logfiles for this taskname
708+
# to stdout. Assuming convention that "taskname" translates to "taskname.log" logfile.
709+
for tid in taskids:
710+
taskspec = self.workflowspec['stages'][tid]
711+
taskname = taskspec['name']
712+
filename = taskname + '.log'
713+
directory = taskspec['cwd']
714+
path = directory + '/' + filename
715+
if os.path.exists(path):
716+
print (' ----> START OF LOGFILE ', path, ' -----')
717+
os.system('cat ' + path)
718+
print (' <---- END OF LOGFILE ', path, ' -----')
719+
702720
def analyse_files_and_connections(self):
703721
for p,s in self.pid_to_files.items():
704722
for f in s:
@@ -906,7 +924,10 @@ def execute(self):
906924

907925
parser.add_argument('--mem-limit', help='Set memory limit as scheduling constraint', default=max_system_mem)
908926
parser.add_argument('--cpu-limit', help='Set CPU limit (core count)', default=8)
909-
parser.add_argument('--cgroup', help='Execute pipeline under a given cgroup (e.g., 8coregrid) emulating resource constraints. This must exist and the tasks file must be writable to with the current user.')
927+
parser.add_argument('--cgroup', help='Execute pipeline under a given cgroup (e.g., 8coregrid) emulating resource constraints. This m\
928+
ust exist and the tasks file must be writable to with the current user.')
929+
parser.add_argument('--stdout-on-failure', action='store_true', help='Print log files of failing tasks to stdout,')
930+
910931
args = parser.parse_args()
911932
print (args)
912933

0 commit comments

Comments
 (0)