Skip to content

Commit 551ea19

Browse files
committed
Adding pipeline hooks to get SLURM job information
1 parent 8963311 commit 551ea19

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

workflow/Snakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ with open(join('config', 'cluster.json')) as fh:
4141

4242
# Imported rules
4343
include: join("rules", "common.smk")
44+
include: join("rules", "hooks.smk")
4445
include: join("rules", "paired-end.smk")
4546

4647
# Targets of the pipeline to build the DAG,
@@ -132,4 +133,4 @@ rule all:
132133
provided(
133134
[join(workpath,"Project","Project.contig.classification.html")],
134135
do_aggregate
135-
)
136+
)

workflow/rules/hooks.smk

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Adding handlers for displaying status of the
2+
# pipeline and for getting job information for
3+
# previously submitted jobs using `jobby`:
4+
# https://github.com/OpenOmics/scribble/blob/main/scripts/jobby/jobby
5+
if config['options']['mode'] == 'slurm':
6+
onstart:
7+
shell(
8+
"""
9+
# Move any job information for a previous
10+
# instance of the pipeline to logfiles
11+
sleep 5; rm -f COMPLETED FAILED RUNNING;
12+
touch RUNNING
13+
for f in job_information_*.tsv; do
14+
# Skip over non-existant files
15+
[ -e "${{f}}" ] || continue
16+
mv ${{f}} logfiles/;
17+
done
18+
19+
for f in failed_jobs_*.tsv; do
20+
# Skip over non-existant files
21+
[ -e "${{f}}" ] || continue
22+
mv ${{f}} logfiles/;
23+
done
24+
"""
25+
)
26+
27+
onsuccess:
28+
shell(
29+
"""
30+
# Get job information on all
31+
# previously submitted jobs
32+
sleep 15; rm -f COMPLETED FAILED RUNNING;
33+
timestamp=$(date +"%Y-%m-%d_%H-%M-%S");
34+
./workflow/scripts/jobby \\
35+
$(grep --color=never "^Submitted .* external jobid" logfiles/snakemake.log \\
36+
| awk '{{print $NF}}' \\
37+
| sed "s/['.]//g" \\
38+
| sort \\
39+
| uniq \\
40+
| tr "\\n" " "
41+
) \\
42+
> job_information_${{timestamp}}.tsv
43+
44+
# Get information on any child
45+
# job(s) that may have failed
46+
grep --color=never \\
47+
'^jobid\\|FAILED' \\
48+
job_information_${{timestamp}}.tsv \\
49+
> failed_jobs_${{timestamp}}.tsv
50+
touch COMPLETED
51+
"""
52+
)
53+
54+
onerror:
55+
shell(
56+
"""
57+
# Get job information on all
58+
# previously submitted jobs
59+
sleep 15; rm -f COMPLETED FAILED RUNNING;
60+
timestamp=$(date +"%Y-%m-%d_%H-%M-%S");
61+
./workflow/scripts/jobby \\
62+
$(grep --color=never "^Submitted .* external jobid" logfiles/snakemake.log \\
63+
| awk '{{print $NF}}' \\
64+
| sed "s/['.]//g" \\
65+
| sort \\
66+
| uniq \\
67+
| tr "\\n" " "
68+
) \\
69+
> job_information_${{timestamp}}.tsv
70+
71+
# Get information on any child
72+
# job(s) that may have failed
73+
grep --color=never \\
74+
'^jobid\\|FAILED' \\
75+
job_information_${{timestamp}}.tsv \\
76+
> failed_jobs_${{timestamp}}.tsv
77+
touch FAILED
78+
"""
79+
)

0 commit comments

Comments
 (0)