use std::sync::LazyLock;
use dex_sdk::{
Channel, Context, Flow, HandlerError, HandlerResult, PersistenceSchema, RetryPolicy, Step,
StepDecision, StepList, StepOptions, Wait,
};
static FIRST: LazyLock<Channel<i32>> = LazyLock::new(|| Channel::new("test-signal-1"));
static SECOND: LazyLock<Channel<i32>> = LazyLock::new(|| Channel::new("test-signal-2"));
static THIRD: LazyLock<Channel<i32>> = LazyLock::new(|| Channel::new("test-signal-3"));
pub(crate) struct AnyCommandCombinationWorkflow {
start: AnyCommandCombinationStep,
}
impl AnyCommandCombinationWorkflow {
pub(crate) fn new() -> Self {
Self {
start: AnyCommandCombinationStep,
}
}
}
impl Flow for AnyCommandCombinationWorkflow {
type StartInput = i32;
fn steps(&self) -> StepList<'_, Self::StartInput> {
StepList::start(&self.start)
}
fn persistence(&self) -> PersistenceSchema {
PersistenceSchema::new()
.channel(&FIRST)
.channel(&SECOND)
.channel(&THIRD)
}
}
struct AnyCommandCombinationStep;
impl Step for AnyCommandCombinationStep {
type Input = i32;
fn wait_for(&self, _context: &mut Context, _input: i32) -> HandlerResult<Wait> {
Err(HandlerError::new(
"UnknownConditionId",
"Found unknown condition ID in the combination list",
))
}
fn execute(&self, _context: &mut Context, input: i32) -> HandlerResult<StepDecision> {
Ok(StepDecision::graceful_complete(input))
}
fn options(&self) -> StepOptions<Self::Input> {
StepOptions::new().wait_for_retry(RetryPolicy::new().maximum_attempts(1))
}
}