Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Invocation id/cancel invocation from Context #27

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pin-project-lite = "0.2"
rand = { version = "0.8.5", optional = true }
regress = "0.10"
restate-sdk-macros = { version = "0.3.0", path = "macros" }
restate-sdk-shared-core = "0.1.0"
restate-sdk-shared-core = { git = "https://github.com/restatedev/sdk-shared-core.git", branch = "issues/cancel-invocation-get-invocation-id" }
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0.63"
Expand Down
7 changes: 6 additions & 1 deletion src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::time::Duration;
mod request;
mod run;

pub use request::{Request, RequestTarget};
pub use request::{CallFuture, InvocationHandle, Request, RequestTarget};
pub use run::{RunClosure, RunFuture, RunRetryPolicy};

pub type HeaderMap = http::HeaderMap<String>;
Expand Down Expand Up @@ -228,6 +228,11 @@ pub trait ContextClient<'ctx>: private::SealedContext<'ctx> {
Request::new(self.inner_context(), request_target, req)
}

/// Create an [`InvocationHandle`] from an invocation id.
fn invocation_handle(&self, invocation_id: String) -> impl InvocationHandle + 'ctx {
self.inner_context().invocation_handle(invocation_id)
}

/// Create a service client. The service client is generated by the [`restate_sdk_macros::service`] macro with the same name of the trait suffixed with `Client`.
///
/// ```rust,no_run
Expand Down
13 changes: 10 additions & 3 deletions src/context/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<'a, Req, Res> Request<'a, Req, Res> {
}

/// Call a service. This returns a future encapsulating the response.
pub fn call(self) -> impl Future<Output = Result<Res, TerminalError>> + Send
pub fn call(self) -> impl CallFuture<Result<Res, TerminalError>> + Send
where
Req: Serialize + 'static,
Res: Deserialize + 'static,
Expand All @@ -96,18 +96,25 @@ impl<'a, Req, Res> Request<'a, Req, Res> {
}

/// Send the request to the service, without waiting for the response.
pub fn send(self)
pub fn send(self) -> impl InvocationHandle
where
Req: Serialize + 'static,
{
self.ctx.send(self.request_target, self.req, None)
}

/// Schedule the request to the service, without waiting for the response.
pub fn send_with_delay(self, duration: Duration)
pub fn send_with_delay(self, duration: Duration) -> impl InvocationHandle
where
Req: Serialize + 'static,
{
self.ctx.send(self.request_target, self.req, Some(duration))
}
}

pub trait InvocationHandle {
fn invocation_id(&self) -> impl Future<Output = Result<String, TerminalError>> + Send;
fn cancel(&self);
}

pub trait CallFuture<O>: Future<Output = O> + InvocationHandle {}
Loading
Loading