Timer
Timer 是持久化在 Dex Server 上的 Durable Timer。等待 Timer 时,Worker 端不会消耗任何资源。
class TimerExampleStep(Step[int]):
def wait_for(self, _context: Context, input: int) -> Wait:
return Wait.until(Timer.by_duration(timedelta(seconds=input)))
def execute(self, context: Context, _input: int) -> StepDecision:
print(context.has_timer_fired())
return graceful_complete("timer-fired")
例子: examples/python/dex_examples/primitives/timer/timer_flow.py
如何跳过 Timer
可以用 Flow ID 和 Timer selector 调用 SkipTimer 跳过 Timer。被跳过的 Timer 就像已经触发一样。这有助于在测试模拟或生产运维中手动触发 Timer。
client.skip_timer(
flow_id,
StepExecutionId("TimerExampleStep"),
TimerId.by_condition_index(0),
)