diff --git a/README.md b/README.md index 0f9ce16..dc8204e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ or as a bsub comment: If you submit an array job with this post-exec script, you'll only be notified once every job in the array has finished. +For more suggestions, see the [`examples` directory](./examples). + ## Preemptively Answered Questions - **I don't use bsub, I use Nextflow** – Nextflow has built-in support for sending notifications when jobs finish. For example: `nextflow run -N you@email.example` diff --git a/examples/bsub.sh b/examples/bsub.sh new file mode 100755 index 0000000..a0b7647 --- /dev/null +++ b/examples/bsub.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +#BSUB -Ep /software/cellgen/cellgeni/etc/notify-slack.sh + +# submit me with e.g.: bsub -o /dev/null < bsub.sh + +echo "hello, $USER" diff --git a/examples/nextflow.nf b/examples/nextflow.nf new file mode 100755 index 0000000..53cdf56 --- /dev/null +++ b/examples/nextflow.nf @@ -0,0 +1,44 @@ +#!/usr/bin/env nextflow + +// This block is the interesting part - copy it into your own script to use Farmer with Nextflow. +workflow.onComplete { + // Modify these variables to control the notification you receive. + def user = workflow.userName + def label = "Nextflow" + def payload = [ + "job name: " + workflow.runName, + "launch dir: " + workflow.launchDir, + "script name: " + workflow.scriptName, + "started: " + workflow.start, + "completed: " + workflow.complete, + "exit status: " + workflow.exitStatus, + workflow.errorMessage ? "error message: " + workflow.errorMessage : null, + ].minus(null).join("\n") + // Leave this code as-is. + URL url = new URL("http://farm22-cgi-01.internal.sanger.ac.uk:8234/job-complete"); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + conn.setDoOutput(true); + conn.connect(); + OutputStream os = conn.getOutputStream(); + String json = groovy.json.JsonOutput.toJson([job_id: null, array_index: null, user_override: user, label: label, payload: payload]); + os.write(json.getBytes("UTF-8")); + os.close(); + conn.getResponseCode() + conn.disconnect(); +} + +// The rest is just a very simple example workflow. +process sayHello { + output: + stdout + + script: + """ + echo 'Hello World!' + """ +} +workflow { + sayHello() +}