Search code examples
javagroovyprocessworkflownextflow

Run python script inside nextflow - workflow.onComplete handler


I want to run a python script at the end of a nextflow workflow using the onComplete handler. This is the code:

workflow.onComplete {
    def proc = "path_to_env/bin/python3 path_to_file/update_run_status.py --run_id ${workflow.runName} --status 'Completed' --secrets_path 'path.toml'".execute() 
    
    if (params.email || params.email_on_fail) NfcoreTemplate.email(workflow, params, summary_params, projectDir, log, multiqc_report)
    NfcoreTemplate.summary(workflow, params, log)
    if (params.hook_url) NfcoreTemplate.IM_notification(workflow, params, summary_params, projectDir, log)
}

If the workflow is complete, no script will be executed, even if there are no errors or warnings.

Has anyone already encountered this problem?

Thanks


Solution

  • Try:

        def proc = [
            'path_to_env/bin/python3',
            'path_to_file/update_run_status.py',
            '--run_id', workflow.runName,
            '--status', 'Completed',
            '--secrets_path', 'path.toml'
        ].execute()
        proc.waitForProcessOutput()
    

    To get all the arguments passed to the processbuilder correctly, and then to wait for the process to finish running