How to change the sleep duration in cadence workflow based on a signal? Is it a proper way using java client?
private int timeout;
@Override
@WorkflowMethod
public void sleepAndWakeUp(int sleepTimeout) {
this.timeout = sleepTimeout;
sleep();
System.out.println("Woken up after " + this.timeout + " s sleep");
}
private void sleep() {
int currentTimeout = this.timeout;
Workflow.await(Duration.ofSeconds(this.timeout), () -> {
boolean cancelTimer = currentTimeout != this.timeout;
if(cancelTimer) {
sleep();
}
return cancelTimer;
});
}
@Override
@SignalMethod
public void snooze(int sleepTimeout) {
this.timeout = sleepTimeout;
}
I have not found other possibility to cancel and reschedule a workflow sleep timer