Skip to content

Commit

Permalink
Clean up startWorkflow API (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: Kaili Zhu <[email protected]>
  • Loading branch information
zklgame and zklgame authored Jul 27, 2023
1 parent b2c3988 commit cdeb5e1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 54 deletions.
66 changes: 12 additions & 54 deletions src/main/java/io/iworkflow/core/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,58 +50,6 @@ public UnregisteredClient getUnregisteredClient() {
return unregisteredClient;
}

/**
* startWorkflow starts a workflow execution
*
* @param workflow is required
* @param workflowId is required
* @param workflowTimeoutSeconds is required
* @return runId
*/
public String startWorkflow(
final ObjectWorkflow workflow,
final String workflowId,
final int workflowTimeoutSeconds) {
return startWorkflow(workflow, workflowId, workflowTimeoutSeconds, null, null);
}

/**
* startWorkflow starts a workflow execution
*
* @param workflow is required
* @param workflowId is required
* @param workflowTimeoutSeconds is required
* @param input is optional, can be null
* @return runId
*/
public String startWorkflow(
final ObjectWorkflow workflow,
final String workflowId,
final int workflowTimeoutSeconds,
final Object input) {
return startWorkflow(workflow, workflowId, workflowTimeoutSeconds, input, null);
}

/**
* startWorkflow starts a workflow execution
*
* @param workflow is required
* @param workflowId is required
* @param workflowTimeoutSeconds is required
* @param input is optional, can be null
* @param options is optional, can be null
* @return runId
*/
public String startWorkflow(
final ObjectWorkflow workflow,
final String workflowId,
final int workflowTimeoutSeconds,
final Object input,
final WorkflowOptions options) {
final String wfType = Registry.getWorkflowType(workflow);
return doStartWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, options);
}

/**
* startWorkflow starts a workflow execution
*
Expand Down Expand Up @@ -151,10 +99,20 @@ public String startWorkflow(
final Object input,
final WorkflowOptions option) {
final String wfType = workflowClass.getSimpleName();
return doStartWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, option);
return startWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, option);
}

private String doStartWorkflow(
/**
* startWorkflow starts a workflow execution
*
* @param wfType is required. It should be the same as the {@link ObjectWorkflow#getWorkflowType()}
* @param workflowId is required
* @param workflowTimeoutSeconds is required
* @param input is optional, can be null
* @param options is optional, can be null
* @return runId
*/
public String startWorkflow(
final String wfType,
final String workflowId,
final int workflowTimeoutSeconds,
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/io/iworkflow/integ/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ public void testEmptyInputWorkflow() throws InterruptedException {
Assertions.fail("get results from a wrong workflow should fail");
}

@Test
public void testTypeSpecifiedWorkflow() {
final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault);
final String wfId = "type-specified-test-id" + System.currentTimeMillis() / 1000;
final UnregisteredWorkflowOptions startOptions = ImmutableUnregisteredWorkflowOptions.builder()
.workflowIdReusePolicy(IDReusePolicy.ALLOW_IF_NO_RUNNING)
.build();

final EmptyInputWorkflow workflow = new EmptyInputWorkflow();

client.startWorkflow(workflow.getWorkflowType(), wfId, 0, null, null);
Integer out = client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
Assertions.assertNull(out);

// fail when not passing the customized workflowType when starting a workflow with customized workflowType
try {
client.startWorkflow(EmptyInputWorkflow.class, wfId, 0);
} catch (final IllegalArgumentException e) {
return;
}
Assertions.fail("not passing the customized workflowType when starting a workflow with customized workflowType should fail");
}

@Test
public void testModelInputWorkflow() throws InterruptedException {
final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault);
Expand Down

0 comments on commit cdeb5e1

Please sign in to comment.