Skip to content

Commit f7d877a

Browse files
huangzhiboclaude
andcommitted
Add WorkflowInterceptor extension point for named workflow interception
Introduce a pf4j ExtensionPoint that allows plugins to intercept named workflow execution. This enables stage-level archiving and resume capabilities without modifying workflow scripts. - Add WorkflowInterceptor interface in nf-commons (ExtensionPoint) - Extract WorkflowDef.runDefault() from run() (pure refactoring) - Add interceptor lookup via Plugins.getExtension() in run() - Entry workflows (name is null) are never intercepted Signed-off-by: Zhibo Huang <huangzhibo@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: huangzhibo <zhibo90@126.com>
1 parent cb7133d commit f7d877a

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import nextflow.exception.MissingProcessException
2424
import nextflow.exception.MissingValueException
2525
import nextflow.exception.ScriptRuntimeException
2626
import nextflow.extension.CH
27+
import nextflow.plugin.Plugins
28+
import nextflow.plugin.WorkflowInterceptor
2729
import nextflow.util.TestOnly
2830
/**
2931
* Models a script workflow component
@@ -181,6 +183,17 @@ class WorkflowDef extends BindableDef implements ChainableDef, IterableDef, Exec
181183
}
182184

183185
Object run(Object[] args) {
186+
final interceptor = name != null ? Plugins.getExtension(WorkflowInterceptor) : null
187+
if( interceptor != null ) {
188+
final result = interceptor.intercept(this, args, { runDefault(args) })
189+
if( result instanceof ChannelOut )
190+
this.output = result
191+
return result
192+
}
193+
return runDefault(args)
194+
}
195+
196+
private Object runDefault(Object[] args) {
184197
binding = new WorkflowBinding(owner)
185198
ExecutionStack.push(this)
186199
try {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package nextflow.plugin
2+
3+
import org.pf4j.ExtensionPoint
4+
5+
/**
6+
* Extension point for intercepting named workflow execution.
7+
*
8+
* Plugins implement this interface to gain control before
9+
* each named workflow runs. The interceptor uses the
10+
* {@code proceed} callback to decide whether to execute
11+
* the original workflow logic:
12+
* - Call {@code proceed()} to execute normally, optionally
13+
* post-processing the result (e.g. archiving)
14+
* - Return without calling {@code proceed()} to skip
15+
* execution (e.g. restore from archive)
16+
*
17+
* Entry workflows (name is null) are never intercepted.
18+
*
19+
* @author Zhibo Huang
20+
*/
21+
interface WorkflowInterceptor extends ExtensionPoint {
22+
23+
/**
24+
* Intercept the execution of a named workflow.
25+
*
26+
* @param workflow the named workflow definition (WorkflowDef)
27+
* @param args the arguments passed to the workflow
28+
* @param proceed callback that executes the original workflow logic
29+
* @return the workflow execution result (ChannelOut)
30+
*/
31+
Object intercept(Object workflow, Object[] args, Closure proceed)
32+
}

0 commit comments

Comments
 (0)