Skip to content

Commit 4855276

Browse files
committed
fork options and javadoc
1 parent 8f953df commit 4855276

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

src/main/java/dev/dbos/transact/DBOS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public void cancelWorkflow(String workflowId) {
373373
*
374374
* @param workflowId Original workflow Id
375375
* @param startStep Start execution from this step. Prior steps copied over
376-
* @param options Forkoptions forkedWorkflowId, applicationVersion, timeout
376+
* @param options {@link ForkOptions} containing forkedWorkflowId, applicationVersion, timeout
377377
* @return handle to the workflow
378378
*/
379379
public WorkflowHandle<?> forkWorkflow(String workflowId, int startStep, ForkOptions options) {

src/main/java/dev/dbos/transact/workflow/ForkOptions.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package dev.dbos.transact.workflow;
22

3+
/**
4+
* Configuration options for forking workflows.
5+
* This class is immutable and uses the Builder pattern for construction.
6+
*/
7+
38
public class ForkOptions {
49
private final String forkedWorkflowId;
510
private final String applicationVersion;
@@ -11,14 +16,29 @@ private ForkOptions(Builder builder) {
1116
this.timeoutMS = builder.timeoutMS;
1217
}
1318

19+
/**
20+
* Gets the forked workflow identifier.
21+
*
22+
* @return the forked workflow ID, may be null
23+
*/
1424
public String getForkedWorkflowId() {
1525
return forkedWorkflowId;
1626
}
1727

28+
/**
29+
* Gets the application version for the forked workflow.
30+
*
31+
* @return the application version, may be null
32+
*/
1833
public String getApplicationVersion() {
1934
return applicationVersion;
2035
}
2136

37+
/**
38+
* Gets the timeout in milliseconds for the forked workflow.
39+
*
40+
* @return the timeout in milliseconds
41+
*/
2242
public long getTimeoutMS() {
2343
return timeoutMS;
2444
}
@@ -27,23 +47,45 @@ public static Builder builder() {
2747
return new Builder();
2848
}
2949

50+
/**
51+
* Builder class for constructing ForkOptions instances.
52+
* Provides a fluent interface for setting configuration values.
53+
*/
3054
public static class Builder {
3155
private String forkedWorkflowId;
3256
private String applicationVersion;
3357
private long timeoutMS;
3458

3559
public Builder() {}
3660

61+
/**
62+
* Sets the forked workflow identifier.
63+
*
64+
* @param forkedWorkflowId the workflow ID to set
65+
* @return this Builder instance for method chaining
66+
*/
3767
public Builder forkedWorkflowId(String forkedWorkflowId) {
3868
this.forkedWorkflowId = forkedWorkflowId;
3969
return this;
4070
}
4171

72+
/**
73+
* Sets the application version for the forked workflow.
74+
*
75+
* @param applicationVersion the application version to set
76+
* @return this Builder instance for method chaining
77+
*/
4278
public Builder applicationVersion(String applicationVersion) {
4379
this.applicationVersion = applicationVersion;
4480
return this;
4581
}
4682

83+
/**
84+
* Sets the timeout in milliseconds for the forked workflow.
85+
*
86+
* @param timeoutMS the timeout in milliseconds
87+
* @return this Builder instance for method chaining
88+
*/
4789
public Builder timeoutMS(long timeoutMS) {
4890
this.timeoutMS = timeoutMS;
4991
return this;

src/test/java/dev/dbos/transact/workflow/WorkflowMgmtTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,12 @@ public void testParentChildFork() {
375375

376376
logger.info("First execution done starting fork") ;
377377

378-
ForkOptions foptions = new ForkOptions.Builder().build() ;
378+
ForkOptions foptions = new ForkOptions.Builder().forkedWorkflowId("f1").build() ;
379379
WorkflowHandle<?> rstatHandle = dbos.forkWorkflow(workflowId, 0, foptions);
380380
result = (String) rstatHandle.getResult() ;
381381
assertEquals("hellohello", result);
382382
assertEquals(WorkflowState.SUCCESS.name(), rstatHandle.getStatus().getStatus());
383-
assertTrue(rstatHandle.getWorkflowId() != workflowId);
383+
assertEquals(rstatHandle.getWorkflowId(), "f1");
384384

385385
assertEquals(2, impl.step1Count) ;
386386
assertEquals(2, impl.step2Count) ;
@@ -396,11 +396,12 @@ public void testParentChildFork() {
396396

397397
logger.info("First execution done starting 2nd fork");
398398

399+
foptions = new ForkOptions.Builder().forkedWorkflowId("f2").build() ;
399400
rstatHandle = dbos.forkWorkflow(workflowId, 3, foptions);
400401
result = (String) rstatHandle.getResult() ;
401402
assertEquals("hellohello", result);
402403
assertEquals(WorkflowState.SUCCESS.name(), rstatHandle.getStatus().getStatus());
403-
assertTrue(rstatHandle.getWorkflowId() != workflowId);
404+
assertEquals(rstatHandle.getWorkflowId(), "f2");
404405

405406
assertEquals(2, impl.step1Count) ;
406407
assertEquals(2, impl.step2Count) ;
@@ -416,13 +417,14 @@ public void testParentChildFork() {
416417
assertTrue(stepsRun0.get(2).getChildWorkflowId().equals(steps.get(2).getChildWorkflowId()));
417418
assertTrue(stepsRun0.get(3).getChildWorkflowId().equals(steps.get(3).getChildWorkflowId()));
418419

419-
logger.info("First execution done starting 2nd fork");
420+
logger.info("2nd execution done starting 3nd fork");
420421

422+
foptions = new ForkOptions.Builder().forkedWorkflowId("f3").build() ;
421423
rstatHandle = dbos.forkWorkflow(workflowId, 4, foptions);
422424
result = (String) rstatHandle.getResult() ;
423425
assertEquals("hellohello", result);
424426
assertEquals(WorkflowState.SUCCESS.name(), rstatHandle.getStatus().getStatus());
425-
assertTrue(rstatHandle.getWorkflowId() != workflowId);
427+
assertEquals(rstatHandle.getWorkflowId(),"f3");
426428

427429
assertEquals(2, impl.step1Count) ;
428430
assertEquals(2, impl.step2Count) ;

0 commit comments

Comments
 (0)