use restate_sdk::prelude::*;
struct SignalExample;
#[restate_sdk::service]
impl SignalExample {
#[handler]
async fn await_approval(&self, ctx: Context<'_>) -> Result<String, HandlerError> {
println!(
"Waiting for approval. Approve with invocation id: {}",
ctx.invocation_id()
);
let decision = ctx.signal::<String>("approval").await?;
Ok(format!("Approved with: {decision}"))
}
#[handler]
async fn approve(&self, ctx: Context<'_>, invocation_id: String) -> Result<(), HandlerError> {
ctx.invocation_handle(invocation_id)
.signal("approval")
.resolve("looks good".to_string());
Ok(())
}
#[handler]
async fn reject(&self, ctx: Context<'_>, invocation_id: String) -> Result<(), HandlerError> {
ctx.invocation_handle(invocation_id)
.signal("approval")
.reject(TerminalError::new("rejected"));
Ok(())
}
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
HttpServer::new(Endpoint::builder().bind(SignalExample).build())
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
.await;
}