Reputation: 841
I want a loop that after each iteration waits for a while. I'm trying to use a timer to do the waiting, but the timer never returns, so the below code only runs once and then waits forever. When I remove the timer condition, the code executes successfully. There are no errors, it just waits...
Any help is appreciated!
@override
public void doWorkflow() {
validate("test", 1);
}
@Asynchronous
private void validate(String id, int retries, Promise<?>... waitFor) {
Promise<Boolean> isValid = activityClient.validate(id);
doWork(id, retries, isValid);
}
@Asynchronous
private void doWork(String id, int retries, Promise<Boolean> isValid) {
if (!isValid.get()) {
return;
}
Promise<Void> waitFor = decisionContext.getWorkflowClock().createTimer(5);
validate(id, retries - 1, waitFor);
}
Upvotes: 0
Views: 365
Reputation: 841
I was using Spring to set up the application. To get the decision context I was using
@Autowired
DecisionContext decisionContext
The problem is when constructing the Workflow implementation I didn't use a scope. The solution was to add the scope="workflow" attribute:
<bean id="myWorkflow" class="com.example.myWorkflowImpl" scope="workflow">
After doing this, the workflow history began showing the TimerStarted event.
Upvotes: 2
Reputation: 6870
I don't see any obvious problems with your code. First I would look at the workflow history (either through console or by printing it using WorkflowExecutionHistoryPrinter) to see if timer is scheduled and if it ever fires. If the history looks OK I would get "asynchronous thread dump" using WorkflowExecutionFlowThreadDumper to see what exactly your code waits for.
Upvotes: 0