Fix script to write outputs to Nextflow work dir

- Save pwd before cd /app so outputs go to correct location
- Use set +e and PIPESTATUS to handle java exit code gracefully
- Exit 0 if FHIR files were generated successfully
This commit is contained in:
2026-03-25 14:51:09 +01:00
parent 02d93f9360
commit f8df39d9af

24
main.nf
View File

@@ -37,20 +37,34 @@ process generatePatients {
def genderArg = params.gender < 0.5 ? "-g M" : (params.gender > 0.5 ? "-g F" : "")
def seedArg = params.seed ? "-s ${params.seed}" : ""
"""
set +e
WORKDIR=\$(pwd)
# Use pre-built jar directly (bypasses Gradle which needs write access to .gradle)
cd /app && java -jar /app/build/libs/synthea-with-dependencies.jar \
cd /app
java -jar /app/build/libs/synthea-with-dependencies.jar \
-p ${params.population} \
${genderArg} \
-a ${params.min_age}-${params.max_age} \
${seedArg} 2>&1 | tee run.log
${seedArg} 2>&1 | tee \${WORKDIR}/run.log
JAVA_EXIT=\${PIPESTATUS[0]}
# Collect FHIR output
# Collect FHIR output back into Nextflow work dir
cd \${WORKDIR}
mkdir -p fhir
if [ -d /app/output/fhir ]; then
cp /app/output/fhir/*.json fhir/ 2>/dev/null || true
echo "Copied \$(ls fhir/*.json 2>/dev/null | wc -l) FHIR bundles" | tee -a run.log
FHIR_COUNT=\$(ls fhir/*.json 2>/dev/null | wc -l)
echo "Copied \${FHIR_COUNT} FHIR bundles" | tee -a run.log
else
echo "Warning: No FHIR output generated" | tee -a run.log
echo "Warning: No FHIR output directory found" | tee -a run.log
fi
# Exit 0 if we got FHIR output, regardless of java exit code
if [ -n "\$(ls fhir/*.json 2>/dev/null)" ]; then
exit 0
else
exit \${JAVA_EXIT}
fi
"""
}