-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfailures.rs
38 lines (31 loc) · 924 Bytes
/
failures.rs
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
use rand::RngCore;
use restate_sdk::prelude::*;
#[restate_sdk::service]
trait FailureExample {
#[name = "doRun"]
async fn do_run() -> Result<(), TerminalError>;
}
struct FailureExampleImpl;
#[derive(Debug, thiserror::Error)]
#[error("I'm very bad, retry me")]
struct MyError;
impl FailureExample for FailureExampleImpl {
async fn do_run(&self, context: Context<'_>) -> Result<(), TerminalError> {
context
.run::<_, _, ()>(|| async move {
if rand::rng().next_u32() % 4 == 0 {
Err(TerminalError::new("Failed!!!"))?
}
Err(MyError)?
})
.await?;
Ok(())
}
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
HttpServer::new(Endpoint::builder().bind(FailureExampleImpl.serve()).build())
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
.await;
}