gwforg / gwf

A flexible, pragmatic workflow tool.
https://gwf.app/
GNU General Public License v3.0
31 stars 12 forks source link

(Edited) Option to log context #416

Open LudvigOlsen opened 1 week ago

LudvigOlsen commented 1 week ago

It could be nice to have an option for logging the target context before executing the call. E.g. to have easy access to the JobID when going through the log of a failed target, and being able to see the called command for debugging or rerunning interactively.

As previously mentioned, I have a pretty large workflow that takes quite a while to do anything with. If I just want to run a job interactively with all the paths and settings filled in by the workflow script, it would be nice to know the exact call (e.g. a python script with lots of paths, etc.).

I've come up with the following wrapper function, that gives me this information. Could something like this be useful to integrate in gwf? This version only works for the slurm backend currently, but it illustrates the idea:

def log_context(call: str):
    escaped_call = call.replace('"', r"\"").replace("'", r"\'").strip()
    return f"""
printf '%s\n' '---'
date
printf "JobID: $SLURM_JOB_ID \n"
printf "Command:\n{escaped_call}\n"
printf '%s' '---\n\n'
{call}
"""

gwf.target('job', inputs=[input_file], outputs=[...]) << log_context("""...""")

Here's an example .stdout output:

billede

LudvigOlsen commented 1 week ago

I edited the issue to be about more general context logging instead of just the command.