mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 11:08:17 +00:00
Merge pull request #1627 from nf-core/fix-prefetch
Use a template to add retrying to prefetch
This commit is contained in:
commit
e36489d9e4
2 changed files with 67 additions and 25 deletions
|
@ -1,43 +1,26 @@
|
||||||
process SRATOOLS_PREFETCH {
|
process SRATOOLS_PREFETCH {
|
||||||
tag "$id"
|
tag "$id"
|
||||||
label 'process_low'
|
label 'process_low'
|
||||||
label 'error_retry'
|
|
||||||
|
|
||||||
conda (params.enable_conda ? 'bioconda::sra-tools=2.11.0' : null)
|
conda (params.enable_conda ? 'bioconda::sra-tools=2.11.0' : null)
|
||||||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
|
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
|
||||||
'https://depot.galaxyproject.org/singularity/sra-tools:2.11.0--pl5262h314213e_0' :
|
'https://depot.galaxyproject.org/singularity/sra-tools:2.11.0--pl5321ha49a11a_3' :
|
||||||
'quay.io/biocontainers/sra-tools:2.11.0--pl5262h314213e_0' }"
|
'quay.io/biocontainers/sra-tools:2.11.0--pl5321ha49a11a_3' }"
|
||||||
|
|
||||||
input:
|
input:
|
||||||
tuple val(meta), val(id)
|
tuple val(meta), val(id)
|
||||||
|
|
||||||
output:
|
output:
|
||||||
tuple val(meta), path("$id"), emit: sra
|
tuple val(meta), path(id), emit: sra
|
||||||
path "versions.yml" , emit: versions
|
path "versions.yml" , emit: versions
|
||||||
|
|
||||||
when:
|
when:
|
||||||
task.ext.when == null || task.ext.when
|
task.ext.when == null || task.ext.when
|
||||||
|
|
||||||
script:
|
shell:
|
||||||
def args = task.ext.args ?: ''
|
args = task.ext.args ?: ''
|
||||||
def config = "/LIBS/GUID = \"${UUID.randomUUID().toString()}\"\\n/libs/cloud/report_instance_identity = \"true\"\\n"
|
args2 = task.ext.args2 ?: '5 1 100' // <num retries> <base delay in seconds> <max delay in seconds>
|
||||||
"""
|
config = "/LIBS/GUID = \"${UUID.randomUUID().toString()}\"\\n/libs/cloud/report_instance_identity = \"true\"\\n"
|
||||||
eval "\$(vdb-config -o n NCBI_SETTINGS | sed 's/[" ]//g')"
|
|
||||||
if [[ ! -f "\${NCBI_SETTINGS}" ]]; then
|
|
||||||
mkdir -p "\$(dirname "\${NCBI_SETTINGS}")"
|
|
||||||
printf '${config}' > "\${NCBI_SETTINGS}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
prefetch \\
|
template 'retry_with_backoff.sh'
|
||||||
$args \\
|
|
||||||
--progress \\
|
|
||||||
$id
|
|
||||||
|
|
||||||
vdb-validate $id
|
|
||||||
|
|
||||||
cat <<-END_VERSIONS > versions.yml
|
|
||||||
"${task.process}":
|
|
||||||
sratools: \$(prefetch --version 2>&1 | grep -Eo '[0-9.]+')
|
|
||||||
END_VERSIONS
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
|
|
59
modules/sratools/prefetch/templates/retry_with_backoff.sh
Executable file
59
modules/sratools/prefetch/templates/retry_with_backoff.sh
Executable file
|
@ -0,0 +1,59 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -u
|
||||||
|
|
||||||
|
retry_with_backoff() {
|
||||||
|
local max_attempts=${1}
|
||||||
|
local delay=${2}
|
||||||
|
local max_time=${3}
|
||||||
|
local attempt=1
|
||||||
|
local output=
|
||||||
|
local status=
|
||||||
|
|
||||||
|
# Remove the first three arguments to this function in order to access
|
||||||
|
# the 'real' command with `${@}`.
|
||||||
|
shift 3
|
||||||
|
|
||||||
|
while [ ${attempt} -le ${max_attempts} ]; do
|
||||||
|
output=$("${@}")
|
||||||
|
status=${?}
|
||||||
|
|
||||||
|
if [ ${status} -eq 0 ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${attempt} -lt ${max_attempts} ]; then
|
||||||
|
echo "Failed attempt ${attempt} of ${max_attempts}. Retrying in ${delay} s." >&2
|
||||||
|
sleep ${delay}
|
||||||
|
elif [ ${attempt} -eq ${max_attempts} ]; then
|
||||||
|
echo "Failed after ${attempt} attempts." >&2
|
||||||
|
return ${status}
|
||||||
|
fi
|
||||||
|
|
||||||
|
attempt=$(( ${attempt} + 1 ))
|
||||||
|
delay=$(( ${delay} * 2 ))
|
||||||
|
if [ ${delay} -ge ${max_time} ]; then
|
||||||
|
delay=${max_time}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "${output}"
|
||||||
|
}
|
||||||
|
|
||||||
|
eval "$(vdb-config -o n NCBI_SETTINGS | sed 's/[" ]//g')"
|
||||||
|
if [[ ! -f "${NCBI_SETTINGS}" ]]; then
|
||||||
|
mkdir -p "$(dirname "${NCBI_SETTINGS}")"
|
||||||
|
printf '!{config}' > "${NCBI_SETTINGS}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
retry_with_backoff !{args2} \
|
||||||
|
prefetch \
|
||||||
|
!{args} \
|
||||||
|
!{id}
|
||||||
|
|
||||||
|
vdb-validate !{id}
|
||||||
|
|
||||||
|
cat <<-END_VERSIONS > versions.yml
|
||||||
|
"!{task.process}":
|
||||||
|
sratools: $(prefetch --version 2>&1 | grep -Eo '[0-9.]+')
|
||||||
|
END_VERSIONS
|
Loading…
Reference in a new issue