Skip to content

Commit aa8f1aa

Browse files
committed
Add preview CLI option (#2914)
This commit adds a new CLI run option `-preview`. When running a workflow script with preview all process executions are skipped. This is useful to evaluate the pipeline execution without actually running. Also when used along with `-with-dag` option it allows the rendering of the execution DAG without running the pipeline. Signed-off-by: Paolo Di Tommaso <[email protected]>
1 parent 4dd1af7 commit aa8f1aa

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

docs/cli.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ the :ref:`k8s-page` section.
783783
+---------------------------+-------------+--------------------------------------------------------------------------------+
784784
| -pod-image | | Specify the container image for the Nextflow pod. |
785785
+---------------------------+-------------+--------------------------------------------------------------------------------+
786+
| -preview | | Run the workflow script skipping the execution of all processes |
787+
+---------------------------+-------------+--------------------------------------------------------------------------------+
786788
| -process. | {} | Set process options. Syntax ``-process.key=value`` |
787789
+---------------------------+-------------+--------------------------------------------------------------------------------+
788790
| -profile | | Choose a configuration profile. |

modules/nextflow/src/main/groovy/nextflow/Session.groovy

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,26 @@ class Session implements ISession {
447447
igniters.add(action)
448448
}
449449

450-
void fireDataflowNetwork() {
450+
void fireDataflowNetwork(boolean preview=false) {
451451
checkConfig()
452452
notifyFlowBegin()
453453

454-
if( !NextflowMeta.instance.isDsl2() )
454+
if( !NextflowMeta.instance.isDsl2() ) {
455455
return
456+
}
456457

457458
// bridge any dataflow queue into a broadcast channel
458459
CH.broadcast()
459460

461+
if( preview ) {
462+
terminated = true
463+
}
464+
else {
465+
callIgniters()
466+
}
467+
}
468+
469+
private void callIgniters() {
460470
log.debug "Ignite dataflow network (${igniters.size()})"
461471
for( Closure action : igniters ) {
462472
try {
@@ -611,15 +621,15 @@ class Session implements ISession {
611621
terminated = true
612622
monitorsBarrier.awaitCompletion()
613623
log.debug "Session await > all barriers passed"
624+
if( !aborted ) {
625+
joinAllOperators()
626+
log.trace "Session > after processors join"
627+
}
614628
}
615629

616630
void destroy() {
617631
try {
618632
log.trace "Session > destroying"
619-
if( !aborted ) {
620-
joinAllOperators()
621-
log.trace "Session > after processors join"
622-
}
623633

624634
// invoke shutdown callbacks
625635
shutdown0()

modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ class CmdRun extends CmdBase implements HubOptions {
237237
@Parameter(names=['-stub-run','-stub'], description = 'Execute the workflow replacing process scripts with command stubs')
238238
boolean stubRun
239239

240+
@Parameter(names=['-preview'], description = "Run the workflow script skipping the execution of all processes")
241+
boolean preview
242+
240243
@Parameter(names=['-plugins'], description = 'Specify the plugins to be applied for this run e.g. nf-amazon,nf-tower')
241244
String plugins
242245

@@ -309,6 +312,7 @@ class CmdRun extends CmdBase implements HubOptions {
309312
// -- create a new runner instance
310313
final runner = new ScriptRunner(config)
311314
runner.setScript(scriptFile)
315+
runner.setPreview(this.preview)
312316
runner.session.profile = profile
313317
runner.session.commandLine = launcher.cliString
314318
runner.session.ansiLog = launcher.options.ansiLog
@@ -350,11 +354,11 @@ class CmdRun extends CmdBase implements HubOptions {
350354
NextflowMeta.instance.enableDsl(dsl)
351355
// -- show launch info
352356
final ver = NF.dsl2 ? DSL2 : DSL1
357+
final head = preview ? "* PREVIEW * $scriptFile.repository" : "Launching `$scriptFile.repository`"
353358
if( scriptFile.repository )
354-
log.info "Launching `$scriptFile.repository` [$runName] DSL${ver} - revision: ${scriptFile.revisionInfo}"
359+
log.info "${head} [$runName] DSL${ver} - revision: ${scriptFile.revisionInfo}"
355360
else
356-
log.info "Launching `$scriptFile.source` [$runName] DSL${ver} - revision: ${scriptFile.getScriptId()?.substring(0,10)}"
357-
361+
log.info "${head} [$runName] DSL${ver} - revision: ${scriptFile.getScriptId()?.substring(0,10)}"
358362
}
359363

360364
static String detectDslMode(ConfigMap config, String scriptText, Map sysEnv) {

modules/nextflow/src/main/groovy/nextflow/script/ScriptRunner.groovy

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class ScriptRunner {
5757
*/
5858
private def result
5959

60+
/**
61+
* Simulate execution and exit
62+
*/
63+
private boolean preview
64+
6065
/**
6166
* Instantiate the runner object creating a new session
6267
*/
@@ -81,6 +86,11 @@ class ScriptRunner {
8186
return this
8287
}
8388

89+
ScriptRunner setPreview(boolean value ) {
90+
this.preview = value
91+
return this
92+
}
93+
8494
Session getSession() { session }
8595

8696
/**
@@ -118,8 +128,10 @@ class ScriptRunner {
118128
parseScript(scriptFile, entryName)
119129
// run the code
120130
run()
121-
// await termination
122-
terminate()
131+
// await completion
132+
await()
133+
// shutdown session
134+
shutdown()
123135
}
124136
catch (Throwable e) {
125137
session.abort(e)
@@ -213,12 +225,17 @@ class ScriptRunner {
213225
// -- normalise output
214226
result = normalizeOutput(scriptParser.getResult())
215227
// -- ignite dataflow network
216-
session.fireDataflowNetwork()
228+
session.fireDataflowNetwork(preview)
217229
}
218230

219-
protected terminate() {
231+
protected await() {
232+
if( preview )
233+
return
220234
log.debug "> Await termination "
221235
session.await()
236+
}
237+
238+
protected shutdown() {
222239
session.destroy()
223240
session.cleanup()
224241
log.debug "> Execution complete -- Goodbye"

0 commit comments

Comments
 (0)