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
//! The trait every task implements.
use crateResult;
use crateTaskContext;
/// A task definition: a named unit of work a workflow can schedule.
///
/// Unlike workflows, tasks may have side effects and perform I/O. Tasks are
/// usually defined with the `#[task]` macro, which generates this
/// implementation; implement it by hand only when you need to.
///
/// # Example
///
/// ```rust
/// use orcher_sdk::prelude::*;
///
/// struct ProcessPaymentTask;
///
/// #[async_trait]
/// impl Task for ProcessPaymentTask {
/// fn name() -> &'static str {
/// "ProcessPayment"
/// }
///
/// async fn execute(ctx: &TaskContext, input: Vec<u8>) -> Result<Vec<u8>> {
/// let order_id: String = serde_json::from_slice(&input)?;
///
/// ctx.heartbeat().await?;
///
/// // Tasks may do I/O, call databases, and so on.
/// let payment_id = process_payment(&order_id).await?;
///
/// let output = serde_json::to_vec(&payment_id)?;
/// Ok(output)
/// }
/// }
/// # async fn process_payment(order_id: &str) -> Result<String> {
/// # Ok(format!("payment-{}", order_id))
/// # }
/// ```