1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! The [`Workflow`] trait.
use crateResult;
use crateWorkflowContext;
/// A workflow definition.
///
/// A workflow is a durable function that orchestrates tasks and other workflows. Side
/// effects belong in tasks, not in the workflow body.
///
/// # Determinism
///
/// A workflow is replayed from its history, so it must be deterministic:
/// - no direct I/O;
/// - no random numbers;
/// - no system clock (use workflow timers and time APIs instead);
/// - no threads or concurrency outside the workflow APIs.
///
/// Most workflows are written with the `#[workflow]` macro, which generates this impl.
///
/// # Example
///
/// ```rust
/// use orcher_sdk::prelude::*;
///
/// struct OrderWorkflow;
///
/// #[async_trait]
/// impl Workflow for OrderWorkflow {
/// fn name() -> &'static str {
/// "OrderWorkflow"
/// }
///
/// async fn execute(ctx: &mut WorkflowContext, input: Vec<u8>) -> Result<Vec<u8>> {
/// let order_id: String = serde_json::from_slice(&input)?;
///
/// let payment_id: String = ctx.execute_task("process_payment", order_id).await?;
///
/// // A durable timer: the wait survives worker restarts.
/// ctx.sleep(std::time::Duration::from_secs(300)).await?;
///
/// let tracking: String = ctx.execute_task("ship_order", payment_id).await?;
///
/// let output = serde_json::to_vec(&tracking)?;
/// Ok(output)
/// }
/// }
/// ```