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

[DSIP-65] SubWorkflow logic task support failover/repeat running/pause/kill/recover #16480

Closed
2 tasks done
Tracked by #14102
ruanwenjun opened this issue Aug 18, 2024 · 0 comments · Fixed by #16566
Closed
2 tasks done
Tracked by #14102

Comments

@ruanwenjun
Copy link
Member

ruanwenjun commented Aug 18, 2024

Search before asking

  • I had searched in the DSIP and found no similar DSIP.

Motivation

Right now the sub workflow doesn't have a good implementation for failover/repeat running/pause/kill/recover, we should redesign this.

Design Detail

The sub workflow task represent a workflow.
image

When the task running, it will create a sub workflow instance, and track its state.

image

And once we trigger/pause/stop/recover the parent workflow we should trigger/pause/stop/recover the sub workflow instance.

Once the sub workflow task running, it will trigger a sub workflow instance. We will use SubWorkflowLogicTaskRuntimeContext to store the sub workflow instance id, so once the task running, we will get the SubWorkflowLogicTaskRuntimeContext, and using the SubWorkflowLogicTaskRuntimeContext to calculate status.

public class SubWorkflowLogicTaskRuntimeContext {

    private Integer subWorkflowInstanceId;

}

When the sub workflow task running, we will trigger the sub workflow by the operation type.

private SubWorkflowLogicTaskRuntimeContext initializeSubWorkflowInstance() {
        // todo: doFailover if the runtime context is not null and task is generated by failover

        if (subWorkflowLogicTaskRuntimeContext == null) {
            return triggerNewSubWorkflow();
        }

        switch (workflowExecutionRunnable.getWorkflowInstance().getCommandType()) {
            case RECOVER_SUSPENDED_PROCESS:
                return recoverFromSuspendTasks();
            case START_FAILURE_TASK_PROCESS:
                return recoverFromFailedTasks();
            default:
                return triggerNewSubWorkflow();
        }

    }

And when we pause/kill the task, we will pause/stop the sub workflow, once the sub workflow instance has been paused/stopped, we can get the status after track status.

@Override
    public void pause() throws MasterTaskExecuteException {
        if (subWorkflowLogicTaskRuntimeContext == null) {
            log.info("subWorkflowLogicTaskRuntimeContext is null cannot pause");
            return;
        }
        final Integer subWorkflowInstanceId = subWorkflowLogicTaskRuntimeContext.getSubWorkflowInstanceId();
        final WorkflowInstancePauseResponse pauseResponse = applicationContext
                .getBean(SubWorkflowControlClient.class)
                .pauseWorkflowInstance(new WorkflowInstancePauseRequest(subWorkflowInstanceId));
        if (pauseResponse.isSuccess()) {
            log.info("Pause sub workflowInstance: id={}", subWorkflowInstanceId + " success");
        } else {
            log.info("Pause sub workflowInstance: id={} failed with response: {}", subWorkflowInstanceId,
                    pauseResponse);
        }
    }

    @Override
    public void kill() throws MasterTaskExecuteException {
        if (subWorkflowLogicTaskRuntimeContext == null) {
            log.info("subWorkflowLogicTaskRuntimeContext is null cannot kill");
            return;
        }
        final Integer subWorkflowInstanceId = subWorkflowLogicTaskRuntimeContext.getSubWorkflowInstanceId();
        final WorkflowInstanceStopResponse stopResponse = applicationContext
                .getBean(SubWorkflowControlClient.class)
                .stopWorkflowInstance(new WorkflowInstanceStopRequest(subWorkflowInstanceId));
        if (stopResponse.isSuccess()) {
            log.info("Kill sub workflowInstance: id={}", subWorkflowInstanceId + " success");
        } else {
            log.info("Kill sub workflowInstance: id={} failed with response: {}", subWorkflowInstanceId, stopResponse);
        }
    }

Compatibility, Deprecation, and Migration Plan

Compatibility with old version.

Test Plan

Test by Master IT.

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant