Skip to content

Commit

Permalink
Add some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sersorrel committed Feb 10, 2025
1 parent 5c3ca8a commit 29f64b7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]`
Expand Down
6 changes: 6 additions & 0 deletions examples/bsub.sh
Original file line number Diff line number Diff line change
@@ -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"
44 changes: 44 additions & 0 deletions examples/nextflow.nf
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 29f64b7

Please sign in to comment.