Skip to content

Commit

Permalink
replace callback with workflow-monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
nebfield committed Aug 10, 2023
1 parent 558b329 commit af850e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
32 changes: 7 additions & 25 deletions data/templates/callback.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@

# set up reporting job status to INTERVENE backend

# need to escape starting curly bracket to prevent templating error
# (the comment above only makes sense in the original template file)
callback_exit_handler() \{
# report the status of the job to the INTERVENE backend
exit_code=$?

if [ $exit_code -eq 0 ]; then
body='\{"status": "COMPLETED", "pipelineId": "{name}", "outdir": ""}'
else
body='\{"status": "FAILED", "pipelineId": "{name}", "outdir": ""}'
fi

# do a callback
url="https://dev.intervenegeneticscores.org/pipeline-manager/pipeline/csc/notify"
# escaping json is a pain
echo $body > callback.txt

curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic $CALLBACK_TOKEN" --data @callback.txt $url

exit $exit_code
}

# run everything in "strict mode". error early, error often!
set -euxo pipefail

trap callback_exit_handler EXIT
# set up reporting job status to INTERVENE backend

# dependencies for workflow-monitor (python3.10 & requests library)
module load python-data/3.10-23.07

# run the monitor in the background
python3 {workflow_monitor_path} &

# ------------------------------------------------------------------------------

13 changes: 6 additions & 7 deletions data/templates/nxf.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

# time to start doing work!

# step 0. load dependencies
# load dependencies
# (curl, jq, and singularity/apptainer are preloaded on Puhti)
module load nextflow/22.10.1
module load parallel

# step 1: transfer data in parallel
# transfer data in parallel
parallel --col-sep ' ' \
-a {work_dir}/{name}/transfer.txt \
java -Xmx256m \
Expand All @@ -23,7 +23,7 @@ set_tmpdir() \{

set_tmpdir

# step 2: run pgsc_calc and calculate some scores
# run pgsc_calc and calculate some scores!
nextflow run {pgsc_calc_dir} -profile singularity \
-c {work_dir}/{name}/allas.config \
-params-file {work_dir}/{name}/params.json \
Expand All @@ -32,9 +32,8 @@ nextflow run {pgsc_calc_dir} -profile singularity \
--min_overlap 0.01 \
--max_cpus 40 \
--max_memory "32.GB" \
--parallel

# step 3: report job status to INTERVENE platform
# (automatically executed in callback_exit_handler by trap)
--parallel \
-with-weblog http://localhost:8000 \
-name {name}

# ------------------------------------------------------------------------------
5 changes: 4 additions & 1 deletion src/slurm/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ struct NextflowContext {
#[derive(Serialize)]
struct CallbackContext {
name: String,
workflow_monitor_path: String
}

/// Write nextflow parameters to working directory
Expand Down Expand Up @@ -236,7 +237,9 @@ fn render_callback(param: &PipelineParam) -> Callback {
let mut tt = TinyTemplate::new();
tt.add_template("callback", CALLBACK).expect("Template");
let name: &String = &param.id;
let context = CallbackContext { name: name.clone() };
static WORKFLOW_MONITOR_PATH: &str = "/scratch/project_2004504/bwingfield/workflow-monitor/main.py";
let context = CallbackContext { name: name.clone(),
workflow_monitor_path: WORKFLOW_MONITOR_PATH.to_string() };
Callback { content: tt.render("callback", &context).expect("Rendered callback") }
}

Expand Down

0 comments on commit af850e6

Please sign in to comment.