maxim
January 5, 2025, 6:22pm
2
At least one problem is that you are not waiting for the children to start before calling continue-as-new. Here is the line of the Java Sample that does this:
// Used to wait for a child start on continue-as-new.
Promise<WorkflowExecution> childStartedPromise = Workflow.getWorkflowExecution(processor);
childrenStartedByThisRun.add(childStartedPromise);
currentRecords.add(record.getId());
// Continues-as-new after starting pageSize children
if (childrenStartedByThisRun.size() == pageSize) {
// Waits for all children to start. Without this wait, workflow completion through
// continue-as-new might lead to a situation when they never start.
// Assumes that they never fail to start as their automatically generated
// IDs are not expected to collide.
Promise.allOf(childrenStartedByThisRun).get();
// Continues as new to keep the history size bounded
ProcessBatchInput newInput = new ProcessBatchInput();
newInput.setPageSize(pageSize);
newInput.setSlidingWindowSize(slidingWindowSize);
newInput.setOffset(offset + childrenStartedByThisRun.size());
newInput.setMaximumOffset(maximumOffset);
newInput.setProgress(progress);
newInput.setCurrentRecords(currentRecords);
return nextRun.processBatch(newInput);
}