nextflow icon indicating copy to clipboard operation
nextflow copied to clipboard

Configure errorStrategy and memory in a process using env vars.

Open pdp10 opened this issue 2 years ago • 3 comments

Hi, I am trying to get this work:

        withName:my_process {
            container = "${env.MY_DOCKER_IMAGE}"
            cpus = "${env.K8S_CPU}"
            memory = { "${env.K8S_MEM_HIGH}" * task.attempt }
            maxRetries = 3
            errorStrategy = { (task.exitStatus in 137..140 && task.attempt <= 3) ? 'retry' : 'ignore' }
        }

but currently have two issues:

  1. Memory. memory = { "${env.K8S_MEM_HIGH}" * task.attempt } does not work whether it is double quoted or not. It only seems to work if the base memory is hard coded, e.g. memory = { 100.MB * task.attempt }.
  2. MaxRetries. It looks like maxRetries cannot be reused in errorStrategy, e.g. (task.exitStatus in 137..140 && task.attempt <= maxRetries). In this case I do not get any error message or retry. The process just terminates with ignore.

Also, ideally, I would like to set maxRetries with an environment variable.

Could you help me figure out what I am doing wrong, please? I've tried so many combinations..

Thanks

pdp10 avatar Mar 01 '22 14:03 pdp10

This seems to work, although it is a bit cluttered.

        withName:my_process {
            container = "${env.MY_DOCKER_IMAGE}"
            cpus = "${env.K8S_PROCESS_CPU}"
            memory = { "${env.K8S_PROCESS_MEMORY_HIGH}" as int * 1.MB * task.attempt }
            maxRetries = "${env.K8S_PROCESS_MAX_RETRIES}"
            errorStrategy = { (task.exitStatus in 137..140 && task.attempt <= "${env.K8S_PROCESS_MAX_RETRIES}" as int) ? 'retry' : 'terminate' }
        }

where:

K8S_PROCESS_MAX_RETRIES=3
K8S_PROCESS_MEMORY_HIGH=100

pdp10 avatar Mar 01 '22 16:03 pdp10

I think the solution you found is basically what you have to do. You might not have to wrap the environment variables, e.g. container = env.MY_DOCKER_IMAGE. You can also leave out maxRetries entirely, you don't really need it when using a custom error strategy like that.

bentsherman avatar Mar 03 '22 16:03 bentsherman

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 31 '22 17:07 stale[bot]