Skip to content

Commit

Permalink
调整IWorkflowExecutor接口
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Oct 19, 2024
1 parent 1539144 commit 82d230c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ default boolean isFlowType() {

void markRead(IServiceContext ctx);

/**
* 调用
* @param args
* @param ctx
*/
void kill(Map<String, Object> args, IServiceContext ctx);

/**
Expand Down Expand Up @@ -185,7 +190,7 @@ default boolean isFlowType() {
void transitTo(String stepName, Map<String, Object> args, IServiceContext ctx);

/**
* 如果本步骤尚未结束,则先结束本步骤。如果本步骤已结束,则直接增加目标步骤实例
* 如果本步骤尚未结束,则结束本步骤,设置状态为指定status
*/
void exitStep(int status, Map<String, Object> args, IServiceContext ctx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface NopWfCoreConstants extends _NopWfCoreConstants {
String INTERNAL_ACTION_TRANSFER_TO_ACTOR = "_transferToActor_";

String INTERNAL_ACTION_TRANSIT = "_transit_";
String INTERNAL_ACTION_TRANSFER_TO_STEP = "_transferToStep_";
String INTERNAL_ACTION_TRANSIT_TO = "_transitTo_";

String VAR_ACTORS = "actors";
String VAR_REJECT_STEPS = "rejectSteps"; // reject action的参数
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package io.nop.wf.core.engine;

import io.nop.api.core.util.FutureHelper;
import io.nop.commons.util.StringHelper;
import io.nop.core.context.IServiceContext;
import io.nop.wf.api.WfReference;
Expand All @@ -28,7 +29,7 @@ public void setWorkflowManager(IWorkflowManager workflowManager) {

@Override
public <T> CompletionStage<T> execute(WfReference wfRef, IServiceContext ctx,
Function<IWorkflow, CompletionStage<T>> task) {
Function<IWorkflow, T> task) {

IWorkflow wf;
if (StringHelper.isEmpty(wfRef.getWfId())) {
Expand All @@ -37,11 +38,11 @@ public <T> CompletionStage<T> execute(WfReference wfRef, IServiceContext ctx,
wf = workflowManager.newWorkflow(wfRef.getWfName(), wfRef.getWfVersion());
}

CompletionStage<T> ret = task.apply(wf);
T ret = task.apply(wf);

// 触发步骤的自动转换
while (wf.runAutoTransitions(ctx)) ;

return ret;
return FutureHelper.toCompletionStage(ret);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.util.Map;
import java.util.Set;

/**
* 单次action调用所对应的上下文对象
*/
public interface IWfRuntime extends IEvalContext {
void delayExecute(Runnable command);

Expand Down Expand Up @@ -65,7 +68,7 @@ default IWfActor getStarter() {
return getWf().getStarter();
}

default String getStarterId(){
default String getStarterId() {
return getWf().getRecord().getStarterId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
*/
public interface IWorkflowExecutor {
<T> CompletionStage<T> execute(WfReference wfRef, IServiceContext ctx,
Function<IWorkflow, CompletionStage<T>> task);
Function<IWorkflow, T> task);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ public void transitTo(IWorkflowStepImplementor step, String stepName,

WfAssignmentModel assignment = stepModel.getAssignment();
List<WfActorWithWeight> actors = getActors(assignment, stepName, wfRt);
if (!this.newSteps(step, stepModel, NopWfCoreConstants.INTERNAL_ACTION_TRANSFER_TO_STEP, actors, wfRt))
if (!this.newSteps(step, stepModel, NopWfCoreConstants.INTERNAL_ACTION_TRANSIT_TO, actors, wfRt))
throw wfRt.newError(ERR_WF_TRANSIT_TO_NO_TARGETS)
.param(ARG_TO_STEP_NAME, step.getStepName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public CompletionStage<WfStartResponseBean> startWorkflowAsync(@RequestBean WfSt
res.setManagerDeptId(manager.getDeptId());
res.setManagerName(manager.getActorName());
}
return FutureHelper.toCompletionStage(res);
return res;
});
}

Expand All @@ -77,7 +77,7 @@ public CompletionStage<Void> notifySubFlowEndAsync(@RequestBean WfSubFlowEndRequ
return workflowExecutor.execute(parentWfRef, ctx, parentWf -> {
IWorkflowStep parentStep = parentWf.getStepById(request.getParentWfStepId());
parentStep.notifySubFlowEnd(request.getStatus(), request.getResults(), ctx);
return FutureHelper.success(null);
return null;
});

}
Expand All @@ -92,7 +92,7 @@ public CompletionStage<Object> invokeActionAsync(
return workflowExecutor.execute(wfRef, ctx, wf -> {
IWorkflowStep step = wf.getStepById(request.getStepId());
Object result = step.invokeAction(request.getActionName(), request.getArgs(), ctx);
return FutureHelper.toCompletionStage(result);
return result;
});
}

Expand All @@ -104,7 +104,7 @@ public CompletionStage<Void> killWorkflowAsync(@RequestBean WfCommandRequestBean
checkMandatory(wfRef, false);
return workflowExecutor.execute(wfRef, ctx, wf -> {
wf.kill(request.getArgs(), ctx);
return FutureHelper.success(null);
return null;
});
}

Expand All @@ -116,7 +116,7 @@ public CompletionStage<Void> suspendWorkflowAsync(@RequestBean WfCommandRequestB
checkMandatory(wfRef, true);
return workflowExecutor.execute(wfRef, ctx, wf -> {
wf.suspend(request.getArgs(), ctx);
return FutureHelper.success(null);
return null;
});
}

Expand All @@ -128,7 +128,7 @@ public CompletionStage<Void> resumeWorkflowAsync(@RequestBean WfCommandRequestBe
checkMandatory(wfRef, true);
return workflowExecutor.execute(wfRef, ctx, wf -> {
wf.resume(request.getArgs(), ctx);
return FutureHelper.success(null);
return null;
});
}

Expand Down

0 comments on commit 82d230c

Please sign in to comment.