Skip to content

Commit

Permalink
Adding pipeline hooks to get SLURM job information
Browse files Browse the repository at this point in the history
  • Loading branch information
skchronicles committed Jul 12, 2023
1 parent 8963311 commit 551ea19
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ with open(join('config', 'cluster.json')) as fh:

# Imported rules
include: join("rules", "common.smk")
include: join("rules", "hooks.smk")
include: join("rules", "paired-end.smk")

# Targets of the pipeline to build the DAG,
Expand Down Expand Up @@ -132,4 +133,4 @@ rule all:
provided(
[join(workpath,"Project","Project.contig.classification.html")],
do_aggregate
)
)
79 changes: 79 additions & 0 deletions workflow/rules/hooks.smk
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Adding handlers for displaying status of the
# pipeline and for getting job information for
# previously submitted jobs using `jobby`:
# https://github.com/OpenOmics/scribble/blob/main/scripts/jobby/jobby
if config['options']['mode'] == 'slurm':
onstart:
shell(
"""
# Move any job information for a previous
# instance of the pipeline to logfiles
sleep 5; rm -f COMPLETED FAILED RUNNING;
touch RUNNING
for f in job_information_*.tsv; do
# Skip over non-existant files
[ -e "${{f}}" ] || continue
mv ${{f}} logfiles/;
done
for f in failed_jobs_*.tsv; do
# Skip over non-existant files
[ -e "${{f}}" ] || continue
mv ${{f}} logfiles/;
done
"""
)

onsuccess:
shell(
"""
# Get job information on all
# previously submitted jobs
sleep 15; rm -f COMPLETED FAILED RUNNING;
timestamp=$(date +"%Y-%m-%d_%H-%M-%S");
./workflow/scripts/jobby \\
$(grep --color=never "^Submitted .* external jobid" logfiles/snakemake.log \\
| awk '{{print $NF}}' \\
| sed "s/['.]//g" \\
| sort \\
| uniq \\
| tr "\\n" " "
) \\
> job_information_${{timestamp}}.tsv
# Get information on any child
# job(s) that may have failed
grep --color=never \\
'^jobid\\|FAILED' \\
job_information_${{timestamp}}.tsv \\
> failed_jobs_${{timestamp}}.tsv
touch COMPLETED
"""
)

onerror:
shell(
"""
# Get job information on all
# previously submitted jobs
sleep 15; rm -f COMPLETED FAILED RUNNING;
timestamp=$(date +"%Y-%m-%d_%H-%M-%S");
./workflow/scripts/jobby \\
$(grep --color=never "^Submitted .* external jobid" logfiles/snakemake.log \\
| awk '{{print $NF}}' \\
| sed "s/['.]//g" \\
| sort \\
| uniq \\
| tr "\\n" " "
) \\
> job_information_${{timestamp}}.tsv
# Get information on any child
# job(s) that may have failed
grep --color=never \\
'^jobid\\|FAILED' \\
job_information_${{timestamp}}.tsv \\
> failed_jobs_${{timestamp}}.tsv
touch FAILED
"""
)

0 comments on commit 551ea19

Please sign in to comment.