-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: run spooker on workflow completion
When a workflow completes (regardless of success or failure), check whether the spooker command is available, and if so, run it to track usage statistics
- Loading branch information
1 parent
e0dd7ba
commit d5c1ce2
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters