Reminder
ReminderFlow 会按 interval 发送提醒,直到接收者 opt-out。ReminderStep 等待 interval Timer 或 OptOut Channel。Timer 先触发时,Step 发送提醒并跳回自身;OptOut 先到达时,Step 完成 Flow。
核心 Step
class ReminderStep(Step[None]):
def __init__(self, service: ServiceDependency, opt_out: Channel[None]) -> None:
self.service = service
self.opt_out = opt_out
def wait_for(self, context: Context, input: None) -> Wait:
del context, input
return Wait.any_of(Timer.by_duration(REMINDER_INTERVAL), self.opt_out.for_one())
def execute(self, context: Context, input: None) -> StepDecision:
del input
if not context.has_timer_fired():
return graceful_complete()
self.service.send_email("Reminder: please respond", "Hello, ...")
return go_to(ReminderStep, None)
例子: examples/python/dex_examples/patterns/reminders/reminder_flow.py