Skip to content

Commit e57ba61

Browse files
sawenzelclaude
andcommitted
Keep the workflow printout in run-workflow-on-inputlist.sh
This is fixing a bug where the printed workflow could be missing from the stdout of run-workflow-on-inputlist.sh. - The output was copied to stdout by a tail started after one second and killed when the workflow ended. - When the workflow had already ended, tail could be killed before printing anything. - tail now follows a sentinel process with --pid, which is stopped only after all processes are done. - The final wait for tail is limited to 10 s, with a warning if it has to be stopped. https://its.cern.ch/jira/browse/O2-7359 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1aae364 commit e57ba61

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

‎prodtests/full-system-test/run-workflow-on-inputlist.sh‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ for i in EXTINPUT CTFINPUT RAWTFINPUT DIGITINPUT; do
2222
done
2323

2424
NUM_PROCS=0
25+
PIDS_LOG=
2526
RETVAL=0
2627
START_TIME=`date +%s`
2728
LOG_PREFIX="log_$(date +%Y%m%d-%H%M%S)_"
@@ -79,13 +80,16 @@ start_process ${DPL_WORKFLOW_FROM_OUTSIDE:-$GEN_TOPO_MYDIR/dpl-workflow.sh}
7980

8081
if [[ "0$4" != "00" ]]; then
8182
sleep 1
82-
tail -n 1000000 -f ${LOG_PREFIX}*.log &
83+
# a sentinel that lives until all processes are done (or this script is gone); tail prints all logs and exits after it
84+
( while kill -0 $$ 2> /dev/null; do sleep 0.5; done ) > /dev/null 2>&1 &
85+
PID_SENTINEL=$!
86+
tail -n 1000000 -f -s 0.1 --pid=$PID_SENTINEL ${LOG_PREFIX}*.log &
87+
PIDS_LOG="$PID_SENTINEL|$!"
8388
ln -sf ${LOG_PREFIX}${NUM_PROCS}.log latest.log
84-
PID_LOG=$!
8589
fi
8690

8791
TIMEOUT_PHASE=0
88-
while [[ `jobs -rl | grep -v " $PID_LOG Running" | wc -l` -ne 0 ]]; do
92+
while [[ -n `jobs -rp | grep -v -x -E "${PIDS_LOG:-none}"` ]]; do
8993
sleep 1
9094
if [[ -n $3 && $(date +%s) -ge $(($START_TIME + $TIMEOUT_PHASE * 20 + $3)) ]]; then
9195
RETVAL=1
@@ -97,8 +101,18 @@ while [[ `jobs -rl | grep -v " $PID_LOG Running" | wc -l` -ne 0 ]]; do
97101
fi
98102
done
99103

104+
# end the sentinel and give tail up to 10 s to print the rest of the logs
100105
if [[ "0$4" != "00" ]]; then
101-
kill $PID_LOG
106+
kill $PID_SENTINEL 2> /dev/null
107+
for i in `seq 1 100`; do
108+
[[ -z `jobs -rp` ]] && break
109+
sleep 0.1
110+
done
111+
if [[ -n `jobs -rp` ]]; then
112+
echo "WARNING: stopping the log output of ${LOG_PREFIX}*.log, it may be incomplete" 1>&2
113+
kill `jobs -rp` 2> /dev/null
114+
fi
115+
wait ${PIDS_LOG//|/ } 2> /dev/null
102116
fi
103117

104118
for i in `seq 1 $NUM_PROCS`; do

0 commit comments

Comments
 (0)