temporalio_client/request_extensions.rs
1//! Request extensions for tonic gRPC requests.
2//!
3//! These types can be inserted into tonic request extensions to modify behavior of retires or other
4//! request handling logic.
5
6use crate::RetryOptions;
7use std::time::Duration;
8
9/// A request extension that, when set, should make the retry behavior consider this call to be a
10/// [CallType::TaskLongPoll](crate::CallType::TaskLongPoll)
11#[derive(Copy, Clone, Debug)]
12pub struct IsWorkerTaskLongPoll;
13
14/// A request extension that, when set, and a call is being processed by a retrying client, allows
15/// the caller to request certain matching errors to short-circuit-return immediately and not follow
16/// normal retry logic.
17#[derive(Copy, Clone, Debug)]
18pub struct NoRetryOnMatching {
19 /// Return true if the passed-in gRPC error should be immediately returned to the caller
20 pub predicate: fn(&tonic::Status) -> bool,
21}
22
23/// A request extension that forces overriding the current retry policy of the [crate::Connection].
24#[derive(Clone, Debug)]
25pub struct RetryConfigForCall(pub RetryOptions);
26
27/// Extension trait for tonic requests to set default timeouts
28pub trait RequestExt {
29 /// Set a timeout for a request if one is not already specified in the metadata
30 fn set_default_timeout(&mut self, duration: Duration);
31}
32
33impl<T> RequestExt for tonic::Request<T> {
34 fn set_default_timeout(&mut self, duration: Duration) {
35 if !self.metadata().contains_key("grpc-timeout") {
36 self.set_timeout(duration)
37 }
38 }
39}