Skip to content

Commit

Permalink
Fix TowerArchiver resolve envar paths relative to baseDir (#3438) [ci…
Browse files Browse the repository at this point in the history
… skip]



Signed-off-by: Jordi Deu-Pons <jordi@jordeu.net>
  • Loading branch information
jordeu committed Nov 29, 2022
1 parent ae95d90 commit 46af18e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
Expand Up @@ -17,6 +17,8 @@

package io.seqera.tower.plugin

import nextflow.exception.AbortOperationException

import java.nio.file.FileAlreadyExistsException
import java.nio.file.Path
import java.time.temporal.ChronoUnit
Expand Down Expand Up @@ -130,26 +132,41 @@ class TowerArchiver {
}

void archiveLogs() {
archiveFile(env.get('NXF_OUT_FILE'))
archiveFile(env.get('NXF_LOG_FILE'))
archiveFile(env.get('NXF_TML_FILE'))
archiveFile(env.get('TOWER_CONFIG_FILE'))
archiveFile(env.get('TOWER_REPORTS_FILE'))
// Nextflow log file are expected to be found at the working directory
// when running from Tower launcher the cache command, if needed, has
// copied them before starting the archive process

final work = env.get('NXF_WORK') ?: env.get('NXF_TEST_WORK')
if( !work ) {
log.error("Missing target work dir - Tower archive cannot be performed")
return
}
if( !work.startsWith('/') ) {
log.error("Invalid NXF_WORK work directory - it must start with a slash character - offending value: '${work}'")
return
}

final base = Path.of(work)
archiveFile(base, env.get('NXF_OUT_FILE'))
archiveFile(base, env.get('NXF_LOG_FILE'))
archiveFile(base, env.get('NXF_TML_FILE'))
archiveFile(base, env.get('TOWER_CONFIG_FILE'))
archiveFile(base, env.get('TOWER_REPORTS_FILE'))
}

void archiveTaskLogs(String workDir) {
final base = Path.of(workDir)
archiveFile(base.resolve('.command.out'))
archiveFile(base.resolve('.command.err'))
archiveFile(base.resolve('.command.log'))
archiveFile(base.resolve('.command.run'))
archiveFile(base.resolve('.command.sh'))
archiveFile(base.resolve('.exitcode'))
archiveFile(base, '.command.out')
archiveFile(base, '.command.err')
archiveFile(base, '.command.log')
archiveFile(base, '.command.run')
archiveFile(base, '.command.sh')
archiveFile(base, '.exitcode')
}

protected void archiveFile(String name) {
protected void archiveFile(Path base, String name) {
if( name )
archiveFile(Path.of(name).toAbsolutePath())
archiveFile(base.resolve(name))
}

protected void archiveFile(Path source) {
Expand Down
Expand Up @@ -17,6 +17,7 @@

package io.seqera.tower.plugin

import java.nio.file.Files
import java.nio.file.Path
import java.util.concurrent.Executors

Expand Down Expand Up @@ -125,4 +126,28 @@ class TowerArchiverTest extends Specification {
target.exists()
}

def 'should archive Nextflow log file' () {
given:
def workDir = Files.createTempDirectory('workdir')
def targetDir = Files.createTempDirectory('target')
def nextflowLog = workDir.resolve('nextflow.log'); nextflowLog.text = 'nextflow logs'
def targetLog = targetDir.resolve('nextflow.log')
and:
def sess = Mock(Session) { getConfig() >> [:] }
def exec = Executors.newSingleThreadExecutor()
def archiver = new TowerArchiver(workDir,targetDir, sess, ['NXF_WORK': workDir.toString(), 'NXF_LOG_FILE': 'nextflow.log'])

when:
archiver.archiveLogs()
sleep 100 // <-- sleep a bit to allow the task to enter in the exec pool
exec.shutdown()

then:
targetLog.exists()

cleanup:
workDir?.deleteDir()
targetDir?.deleteDir()
}

}

0 comments on commit 46af18e

Please sign in to comment.