From a19d79f6ffcf1f7c20033e9247a21e2119a0941d Mon Sep 17 00:00:00 2001 From: Bruno Grande Date: Thu, 23 Jun 2022 09:44:16 -0700 Subject: [PATCH] Move `check_max()` to global config --- conf/sage.config | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/conf/sage.config b/conf/sage.config index 3b2a423..b559f79 100644 --- a/conf/sage.config +++ b/conf/sage.config @@ -64,3 +64,37 @@ params { def slow(attempt, factor = 2) { return Math.ceil( attempt / factor) as int } + + +// Function to ensure that resource requirements don't go +// beyond a maximum limit +def check_max(obj, type) { + if (type == 'memory') { + try { + if (obj.compareTo(params.max_memory as nextflow.util.MemoryUnit) == 1) + return params.max_memory as nextflow.util.MemoryUnit + else + return obj + } catch (all) { + println " ### ERROR ### Max memory '${params.max_memory}' is not valid! Using default value: $obj" + return obj + } + } else if (type == 'time') { + try { + if (obj.compareTo(params.max_time as nextflow.util.Duration) == 1) + return params.max_time as nextflow.util.Duration + else + return obj + } catch (all) { + println " ### ERROR ### Max time '${params.max_time}' is not valid! Using default value: $obj" + return obj + } + } else if (type == 'cpus') { + try { + return Math.min( obj, params.max_cpus as int ) + } catch (all) { + println " ### ERROR ### Max cpus '${params.max_cpus}' is not valid! Using default value: $obj" + return obj + } + } +}