gpt4 book ai didi

java - 在 Java 客户端的 uber cadence 工作流中取消和重新安排 sleep 时间

转载 作者:行者123 更新时间:2023-12-04 10:19:32 25 4
gpt4 key购买 nike

如何根据信号更改节奏工作流程中的 sleep 持续时间?这是使用java客户端的正确方法吗?

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;
}

我还没有找到取消和重新安排工作流 sleep 计时器的其他可能性

最佳答案

这是来自 Temporal Java Samples 的代码:

public final class UpdatableTimer {

private long wakeUpTime;
private boolean wakeUpTimeUpdated;

public void sleepUntil(long wakeUpTime) {
this.wakeUpTime = wakeUpTime;
do {
wakeUpTimeUpdated = false;
Duration sleepInterval = Duration.ofMillis(this.wakeUpTime - Workflow.currentTimeMillis());
if (!Workflow.await(sleepInterval, () -> wakeUpTimeUpdated)) {
break;
}
} while (wakeUpTimeUpdated);
}

public void updateWakeUpTime(long wakeUpTime) {
this.wakeUpTime = wakeUpTime;
this.wakeUpTimeUpdated = true;
}

public long getWakeUpTime() {
return wakeUpTime;
}
}

关于java - 在 Java 客户端的 uber cadence 工作流中取消和重新安排 sleep 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60924795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com