pub struct CallContext { /* private fields */ }Expand description
Everything one backend call needs: timeout, deadline, retry policy, cancel token, round-trip recorder and redactor. Cheap to clone.
Build one with CallContext::new and the with_* methods; run a call
with call. See the module docs.
Implementations§
Source§impl CallContext
impl CallContext
Sourcepub fn new() -> Self
pub fn new() -> Self
A context with nothing set: a DEFAULT_CALL_TIMEOUT attempt timeout,
one attempt, no cancel token, no deadline, no metering.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Bound each attempt by timeout. An attempt that runs out fails with a
retriable FaucetError::Timeout.
Sourcepub fn without_timeout(self) -> Self
pub fn without_timeout(self) -> Self
Let each attempt run as long as it takes. For a call that legitimately outlives any fixed bound (a long poll, a streamed download); a deadline still applies.
Sourcepub fn with_deadline(self, deadline: Instant) -> Self
pub fn with_deadline(self, deadline: Instant) -> Self
End the whole call — every attempt and every backoff — at deadline,
with a FaucetError::Timeout.
Sourcepub fn with_retry(self, policy: RetryPolicy) -> Self
pub fn with_retry(self, policy: RetryPolicy) -> Self
Retry failed attempts under policy: classified by
RetryClass, backed off with jitter, and a
FaucetError::RateLimited waits the time it states.
Sourcepub fn without_retry(self) -> Self
pub fn without_retry(self) -> Self
Make exactly one attempt, whatever a layered context says.
Sourcepub fn with_rate_limit_retries(self, n: u32) -> Self
pub fn with_rate_limit_retries(self, n: u32) -> Self
Give rate limits their own budget: a FaucetError::RateLimited
outcome waits its stated time and is retried up to n consecutive
times without using one of the retry policy’s attempts (any other
outcome resets the count). Without this, a rate limit is an ordinary
retriable attempt.
Sourcepub fn with_cancel(self, cancel: CancellationToken) -> Self
pub fn with_cancel(self, cancel: CancellationToken) -> Self
Stop the call, and any backoff, as soon as cancel fires, with
FaucetError::Cancelled.
Sourcepub fn with_recorder(self, recorder: Arc<RoundtripRecorder>) -> Self
pub fn with_recorder(self, recorder: Arc<RoundtripRecorder>) -> Self
Count each attempt as a round trip, and report throttling and retries,
on recorder.
Sourcepub fn with_roundtrip_metering(self, on: bool) -> Self
pub fn with_roundtrip_metering(self, on: bool) -> Self
Whether call counts each attempt as a round trip
(default true). Throttling and retries are reported either way; turn
this off for a call whose round trips the connector counts itself.
Sourcepub fn with_redactor(self, redactor: CallRedactor) -> Self
pub fn with_redactor(self, redactor: CallRedactor) -> Self
Scrub error text with redactor instead of the process-wide hook
(crate::redact::redact).
Sourcepub fn inherit(&self, base: &CallContext) -> CallContext
pub fn inherit(&self, base: &CallContext) -> CallContext
This context with every field it leaves unset taken from base.
Sourcepub fn timeout(&self) -> Option<Duration>
pub fn timeout(&self) -> Option<Duration>
The attempt timeout, None when attempts are unbounded.
Sourcepub fn retry(&self) -> Option<&RetryPolicy>
pub fn retry(&self) -> Option<&RetryPolicy>
The retry policy, when one is set (None = a single attempt).
Sourcepub fn rate_limit_retries(&self) -> Option<u32>
pub fn rate_limit_retries(&self) -> Option<u32>
The rate-limit budget set by
with_rate_limit_retries.
Sourcepub fn cancel(&self) -> Option<&CancellationToken>
pub fn cancel(&self) -> Option<&CancellationToken>
The cancel token, when one is set.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether the cancel token has fired.
Sourcepub fn recorder(&self) -> Option<&Arc<RoundtripRecorder>>
pub fn recorder(&self) -> Option<&Arc<RoundtripRecorder>>
The round-trip recorder, when one is set.
Sourcepub fn signal(&self, kind: &'static str, unit: &'static str, quantity: f64)
pub fn signal(&self, kind: &'static str, unit: &'static str, quantity: f64)
Report a backend-measured usage figure (see
RoundtripRecorder::signal).
Sourcepub fn redact(&self, text: &str) -> String
pub fn redact(&self, text: &str) -> String
Scrub text with this context’s redactor, or the process-wide one.
Sourcepub fn redact_error(&self, err: FaucetError) -> FaucetError
pub fn redact_error(&self, err: FaucetError) -> FaucetError
err with the text it carries scrubbed: the URL and body of an HTTP
status error, and the URL of a transport error (credentials in it are
removed too).
Sourcepub async fn wait(&self, duration: Duration) -> Result<(), FaucetError>
pub async fn wait(&self, duration: Duration) -> Result<(), FaucetError>
Wait duration the way a call waits: ended early with
FaucetError::Cancelled when the token fires, and with
FaucetError::Timeout when the deadline comes first. For a pause that
is not a retry — a poll interval, a server-requested pacing delay.
Sourcepub async fn call<T, F, Fut>(
&self,
op: &'static str,
f: F,
) -> Result<T, FaucetError>
pub async fn call<T, F, Fut>( &self, op: &'static str, f: F, ) -> Result<T, FaucetError>
Run f as one backend call named op (a closed, connector-defined
label such as query, page, put).
Each invocation of f is one attempt. The call:
- fails fast with
FaucetError::Cancelledwhen the token has fired, and stops an attempt or a backoff the moment it fires; - bounds each attempt by the attempt timeout and the whole call by the
deadline (
FaucetError::Timeout, retriable while the deadline allows); - retries under the retry policy: classified errors only, jittered
backoff, a
FaucetError::RateLimitedwaiting its stated time; - counts every attempt as a round trip on the recorder (with its duration), and every throttle, throttle wait and retry;
- scrubs the final error (
redact_error).
Sourcepub async fn call_once<T, Fut>(
&self,
op: &'static str,
fut: Fut,
) -> Result<T, FaucetError>
pub async fn call_once<T, Fut>( &self, op: &'static str, fut: Fut, ) -> Result<T, FaucetError>
Run fut as one backend call named op, in a single attempt: the
form for a call that cannot be rebuilt — a statement on a borrowed
transaction, a step of a cursor or stream, a non-idempotent write.
Timeout, deadline, cancel, metering and redaction apply as in
call; any retry policy is ignored.
Source§impl CallContext
impl CallContext
Sourcepub fn reader<R>(&self, inner: R) -> CallReader<R>
pub fn reader<R>(&self, inner: R) -> CallReader<R>
inner read under this context (CallReader).
Trait Implementations§
Source§impl Clone for CallContext
impl Clone for CallContext
Source§impl Debug for CallContext
impl Debug for CallContext
Source§impl Default for CallContext
impl Default for CallContext
impl RefUnwindSafe for CallContext
impl UnwindSafe for CallContext
Auto Trait Implementations§
impl Freeze for CallContext
impl Send for CallContext
impl Sync for CallContext
impl Unpin for CallContext
impl UnsafeUnpin for CallContext
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request