// Setting default labels with associated resource allocation

process {

    // Default resources are same as single label for any unlabelled processes that may be added
    cpus   = { check_max( 1    * task.attempt, 'cpus'   ) }
    memory = { check_max( 2.GB * task.attempt, 'memory' ) }
    time   = { check_max( 1.h  * task.attempt, 'time'   ) }

    // If error is due to timeout or exceeding resource limits then retry
    errorStrategy = { task.exitStatus in ((130..145) + 104) ? 'retry' : 'finish' }
    maxRetries    = 1
    // Do not allow any errors when retrying
    maxErrors     = '-1'

    withLabel:process_single {
        cpus   = { check_max( 1    * task.attempt, 'cpus'   ) }
        memory = { check_max( 2.GB * task.attempt, 'memory' ) }
        time   = { check_max( 1.h  * task.attempt, 'time'   ) }
    }
    withLabel:process_low {
        cpus   = { check_max( 2     * task.attempt, 'cpus'    ) }
        memory = { check_max( 4.GB  * task.attempt, 'memory'  ) }
        time   = { check_max( 2.h   * task.attempt, 'time'    ) }
    }
    withLabel:process_medium {
        cpus   = { check_max( 4     * task.attempt, 'cpus'    ) }
        memory = { check_max( 8.GB  * task.attempt, 'memory'  ) }
        time   = { check_max( 4.h   * task.attempt, 'time'    ) }
    }
    withLabel:process_high {
        cpus   = { check_max( 8     * task.attempt, 'cpus'    ) }
        memory = { check_max( 12.GB * task.attempt, 'memory'  ) }
        time   = { check_max( 8.h   * task.attempt, 'time'    ) }
    }
    withLabel:process_med_long {
        time   = { check_max( 24.h  * task.attempt, 'time'    ) }
    }
    withLabel:process_high_cpu {
        cpus   = { check_max( 16    * task.attempt, 'cpus'    ) }
    }
    withLabel:process_long {
        time   = { check_max( 48.h  * task.attempt, 'time'    ) }
    }
    withLabel:process_high_memory {
        memory = { check_max( 64.GB  * task.attempt, 'memory' ) }
    }
    withLabel:error_ignore {
        errorStrategy = 'ignore'
    }
    withLabel:error_retry {
        errorStrategy = 'retry'
        maxRetries    = 2
    }

}
