Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow closures in file/url for trace,report,timeline,dag,weblog #3651

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ The following settings are available:
: When `true` turns on the generation of the DAG file (default: `false`).

`dag.file`
: Graph file name (default: `dag-<timestamp>.dot`).
: Graph file name or closure returning the file name (default: `dag-<timestamp>.dot`).

`dag.overwrite`
: When `true` overwrites any existing DAG file with the same name.
Expand Down Expand Up @@ -1245,7 +1245,7 @@ The following settings are available:
: If `true` it create the workflow execution report.

`report.file`
: The path of the created execution report file (default: `report-<timestamp>.html`).
: Report file name or closure returning the file name (default: `report-<timestamp>.html`).

`report.overwrite`
: When `true` overwrites any existing report file with the same name.
Expand Down Expand Up @@ -1358,7 +1358,7 @@ The following settings are available:
: When `true` enables the generation of the timeline report file (default: `false`).

`timeline.file`
: Timeline file name (default: `timeline-<timestamp>.html`).
: Timeline file name or closure returning the file name (default: `timeline-<timestamp>.html`).

`timeline.overwrite`
: When `true` overwrites any existing timeline file with the same name.
Expand Down Expand Up @@ -1402,7 +1402,7 @@ The following settings are available:
: Comma separated list of fields to be included in the report. The available fields are listed at {ref}`this page <trace-fields>`.

`trace.file`
: Trace file name (default: `trace-<timestamp>.txt`).
: Trace file name or closure returning the file name (default: `trace-<timestamp>.txt`).

`trace.overwrite`
: When `true` overwrites any existing trace file with the same name.
Expand Down
10 changes: 7 additions & 3 deletions modules/nextflow/src/main/groovy/nextflow/Session.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,17 @@ class Session implements ISession {
this.disableRemoteBinDir = getExecConfigProp(null, 'disableRemoteBinDir', false)
this.classesDir = FileHelper.createLocalDir()
this.executorFactory = new ExecutorFactory(Plugins.manager)
this.observers = createObservers()
this.statsEnabled = observers.any { it.enableMetrics() }
this.workflowMetadata = new WorkflowMetadata(this, scriptFile)

// configure script params
// configure script binding
binding.setParams( (Map)config.params )
binding.setArgs( new ScriptRunner.ArgsList(args) )
binding.setVariable( 'nextflow', NextflowMeta.instance )
binding.setVariable( 'workflow', workflowMetadata )

// configure observers
this.observers = createObservers()
this.statsEnabled = observers.any { it.enableMetrics() }

cache = CacheFactory.create(uniqueId,runName).open()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DefaultObserverFactory implements TraceObserverFactory {
if( !isEnabled )
return

String fileName = config.navigate('report.file')
String fileName = config.navigateDynamic('report.file', session.binding)
def maxTasks = config.navigate('report.maxTasks', ReportObserver.DEF_MAX_TASKS) as int
if( !fileName ) fileName = ReportObserver.DEF_FILE_NAME
def report = (fileName as Path).complete()
Expand All @@ -61,7 +61,7 @@ class DefaultObserverFactory implements TraceObserverFactory {
if( !isEnabled )
return

String fileName = config.navigate('timeline.file')
String fileName = config.navigateDynamic('timeline.file', session.binding)
if( !fileName ) fileName = TimelineObserver.DEF_FILE_NAME
def traceFile = (fileName as Path).complete()
def observer = new TimelineObserver(traceFile)
Expand All @@ -74,7 +74,7 @@ class DefaultObserverFactory implements TraceObserverFactory {
if( !isEnabled )
return

String fileName = config.navigate('dag.file')
String fileName = config.navigateDynamic('dag.file', session.binding)
if( !fileName ) fileName = GraphObserver.DEF_FILE_NAME
def traceFile = (fileName as Path).complete()
def observer = new GraphObserver(traceFile)
Expand All @@ -90,7 +90,7 @@ class DefaultObserverFactory implements TraceObserverFactory {
if( !isEnabled )
return

String fileName = config.navigate('trace.file')
String fileName = config.navigateDynamic('trace.file', session.binding)
if( !fileName ) fileName = TraceFileObserver.DEF_FILE_NAME
def traceFile = (fileName as Path).complete()
def observer = new TraceFileObserver(traceFile)
Expand Down
7 changes: 7 additions & 0 deletions modules/nf-commons/src/main/nextflow/extension/Bolts.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,13 @@ class Bolts {
return result!=null ? result : defValue
}

static def navigateDynamic(Map self, String key, binding, defValue = null) {
def result = navigate(self, key, defValue)
return result instanceof Closure
? cloneWith(result, binding).call()
: result
}

/**
* Converts {@code ConfigObject}s to a plain {@code Map}
*
Expand Down
9 changes: 9 additions & 0 deletions tests/checks/dynamic-trace-filepath.nf/.checks
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -e

echo ''
$NXF_RUN -c ../../dynamic-trace-filepath.config | tee stdout

session_id=$(grep "DEBUG nextflow.Session - Run name:" .nextflow.log | sed 's/.* //')
expected="tracedir-${session_id}-foo/trace.txt"

[[ `grep DEBUG .nextflow.log | grep 'Workflow started -- trace file:' | sed 's/.* //'` == *${expected} ]] || false
8 changes: 8 additions & 0 deletions tests/dynamic-trace-file.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
params {
test = "foo"
}

trace {
enabled = true
file = { "tracedir-${workflow.runName}-${params.test}/trace.txt" }
}
25 changes: 25 additions & 0 deletions tests/dynamic-trace-file.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env nextflow
/*
* Copyright 2020-2022, Seqera Labs
* Copyright 2013-2019, Centre for Genomic Regulation (CRG)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

process foo {
"""
echo Hello
"""
}

workflow { foo() }