diff --git a/nextflow/README.md b/nextflow/README.md index 106c51b..3c6941d 100644 --- a/nextflow/README.md +++ b/nextflow/README.md @@ -185,6 +185,13 @@ the name it was published under. The dataset's path in this tree (`folderA/folde also recorded *inside* each checkpoint as its own name, so the two fixed filenames stay unambiguous — reopening either one shows the dataset it holds, not the word "results". +Only the checkpoints that the dataset's `results.log` records as saved (`[ok] saved …`) +are published and listed in `index.json`. AWS Batch can run a task's job a second time +in the same work directory, for instance when a spot instance is reclaimed during the +upload, and the earlier attempt's files stay there. A checkpoint's hash differs from one +attempt to the next, so without this check the dataset would be published with two +checkpoints of each kind. + Serving the `results/` directory over HTTP — any static host — renders every dataset in the browser with no backend (DESIGN §14.3). The same `.zarr.zip` files also open in the full app (New Session → Load) when you need to compute on them. diff --git a/nextflow/main.nf b/nextflow/main.nf index 55cf000..8d5d8c1 100644 --- a/nextflow/main.nf +++ b/nextflow/main.nf @@ -42,6 +42,23 @@ def asciiPath(String prefix) { .replaceAll('[^\\x20-\\x7E]+', '-') } +/** Whether ANALYSE's last attempt wrote `checkpoint`, by its `[ok] saved` line in the + * results.log beside it. Any other file is not a checkpoint and is kept. + * + * AWS Batch can run a task's job a second time in the same S3 work directory (a spot + * instance reclaimed mid-upload). Each attempt stages out what it wrote without + * removing what an earlier attempt left there, and a checkpoint is named by a hash of + * its content, which differs between attempts, so the output glob would pick up both. + * results.log has a fixed name and is rewritten from empty by every attempt. + */ +def savedByLastAttempt(Path checkpoint) { + if( !checkpoint.name.endsWith('.zarr.zip') ) return true + def results_log = checkpoint.resolveSibling('results.log') + return results_log.exists() && results_log.readLines().any { line -> + line.startsWith('[ok] saved ') && line.contains("/${checkpoint.name} (") + } +} + process ANALYSE { tag "${prefix} (${spec.label})" container params.analysis_container @@ -49,7 +66,10 @@ process ANALYSE { // Everything this candidate produces is already laid out under out/ exactly as it // should be published, so publishing is a straight copy with the wrapper stripped. publishDir "${params.outdir}/results", mode: 'copy', pattern: 'out/**', - saveAs: { f -> f.toString().tokenize('/').drop(1).join('/') } + saveAs: { f -> + savedByLastAttempt(task.workDir.resolve(f)) + ? f.toString().tokenize('/').drop(1).join('/') : null + } input: tuple val(prefix), val(spec), path(data_dir) @@ -423,8 +443,8 @@ workflow { // The full checkpoint and its low-res copy are separate entries in the listing. ANALYSE.out.published .flatten() + .filter { f -> f.name.endsWith('.zarr.zip') && savedByLastAttempt(f) } .map { f -> f.toString() } - .filter { f -> f.endsWith('.zarr.zip') } .map { f -> def rel = f.substring(f.indexOf('/out/') + '/out/'.length()) // Both checkpoints of a dataset sit in its own folder, so the folder