Skip to content

Commit

Permalink
Merge pull request #17 from CCBR/spooker
Browse files Browse the repository at this point in the history
feat: run spooker on workflow completion
  • Loading branch information
dnousome authored Nov 28, 2023
2 parents fe841fb + d5c1ce2 commit d13c701
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/Utils.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Utils {
// run spooker for the workflow
public static String spooker(workflow) {
def pipeline_name = "${workflow.manifest.name.tokenize('/')[-1]}"
def command_string = "spooker ${workflow.launchDir} ${pipeline_name}"
def out = new StringBuilder()
def err = new StringBuilder()
def spooker_in_path = check_command_in_path("spooker")
if (spooker_in_path) {
try {
println "Running spooker"
def command = command_string.execute()
command.consumeProcessOutput(out, err)
command.waitFor()
} catch(IOException e) {
err = e
}
new FileWriter("${workflow.launchDir}/log/spooker.log").with {
write("${out}\n${err}")
flush()
}
} else {
err = "spooker not found, skipping"
}
return err
}
// check whether a command is in the path
public static Boolean check_command_in_path(cmd) {
def command_string = "command -V ${cmd}"
def out = new StringBuilder()
def err = new StringBuilder()
try {
def command = command_string.execute()
command.consumeProcessOutput(out, err)
command.waitFor()
} catch(IOException e) {
err = e
}
return err.length()==0

}
}
8 changes: 8 additions & 0 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ log.info """\
"""
.stripIndent()

workflow.onComplete {
if (!workflow.stubRun && !workflow.commandLine.contains('-preview')) {
def message = Utils.spooker(workflow)
if (message) {
println message
}
}
}

//Final Workflow
workflow {
Expand Down

0 comments on commit d13c701

Please sign in to comment.