Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inst/templates/workflow/SWF/controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ make_env_cur_vars "$SWF_CUR"
# Run the next sbatch job
if [[ -f "$SWF__JOB_SCRIPT" ]]
then
# Archive old log files for this step before submitting
archive_old_logs "${SWF_NAME}_step${SWF_CUR}" "$SLURM_JOB_ID" "$SWF_LOG_DIR"

sbatch --dependency=afterany:"$SLURM_JOB_ID" \
--output="$SWF__STEPS_OUT" \
--job-name="${SWF_NAME}_step${SWF_CUR}" \
Expand Down
30 changes: 30 additions & 0 deletions inst/templates/workflow/SWF/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@ function make_env_cur_vars {
export SWF__INSTRUCTIONS_SCRIPT="$SWF__CUR_DIR/instructions.sh"
}

# Archive old log files for a step before resubmitting it.
# Moves .out files with a job ID lower than the current one to log/archive/.
# Arguments:
# $1 - step name (e.g., "wf_name_step1")
# $2 - current SLURM job ID (files with lower IDs are considered old)
# $3 - log directory path
function archive_old_logs {
local step_name="$1"
local current_jobid="$2"
local log_dir="$3"
local archive_dir="$log_dir/archive"

for f in "$log_dir"/${step_name}_*.out; do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not a valid bash line. You can't index out of a glob.
find "$log_dir" -name "${step_name}_*.out" actually list them.
This can be stored in a variable then iterated on

[ -f "$f" ] || continue

local basename
basename=$(basename "$f")
# Remove the step_name_ prefix and .out suffix to get JOBID_TASKID
local remainder="${basename#${step_name}_}"
remainder="${remainder%.out}"
# Extract the job ID (part before the first _)
local file_jobid="${remainder%%_*}"

if [[ "$file_jobid" =~ ^[0-9]+$ ]] && [ "$file_jobid" -lt "$current_jobid" ]; then
mkdir -p "$archive_dir"
mv "$f" "$archive_dir/"
fi
done
}

# convert CRLF endings to LF - `|| echo ""` prevents error when none is found
function fix_crlf_files {
local CRLF_FILES=$(find "$1" -type f | xargs file -F "::" | grep CRLF || echo "")
Expand Down
Loading