pub struct FaultRuntime { /* private fields */ }Expand description
The validated fault-tolerance capability installed on a chunk step.
The bundle owns the policy, the injected monotonic sleeper, the reservation store, and the declared delivery mode. Capabilities are validated at construction so a statically impossible combination cannot reach user work.
use std::sync::Arc;
use std::time::Duration;
use oxide_batch::{
BackoffOutcome, BackoffPolicy, BackoffSleeper, BoxFuture, ChunkDeliveryMode,
ClassifierRevision, FailureCategory, FaultAction, FaultClassifier, FaultPhase, FaultPolicy,
FaultRule, FaultRuntime, InMemoryFaultState, RetryLimit, RetryStateLimit, SkipLimit,
StopToken,
};
struct ImmediateSleeper;
impl BackoffSleeper for ImmediateSleeper {
fn sleep<'a>(
&'a self,
_delay: Duration,
stop: &'a StopToken,
) -> BoxFuture<'a, BackoffOutcome> {
let stopped = stop.is_stop_requested();
Box::pin(async move {
if stopped { BackoffOutcome::Stopped } else { BackoffOutcome::Elapsed }
})
}
}
let policy = FaultPolicy::new(
FaultClassifier::new(
ClassifierRevision::new("import_v1")?,
[FaultRule::new(
FaultPhase::Write,
FailureCategory::Timeout,
FaultAction::retry(),
)?],
)?,
RetryLimit::new(2)?,
RetryStateLimit::new(16)?,
SkipLimit::NONE,
BackoffPolicy::fixed(Duration::from_millis(10))?,
)?;
let state = Arc::new(InMemoryFaultState::new(policy.retry_state_limit()));
let runtime = FaultRuntime::new(
policy,
Arc::new(ImmediateSleeper),
state,
ChunkDeliveryMode::AtLeastOnce,
)?;
assert_eq!(runtime.delivery_mode(), ChunkDeliveryMode::AtLeastOnce);Implementations§
Source§impl FaultRuntime
impl FaultRuntime
Sourcepub fn new(
policy: FaultPolicy,
sleeper: Arc<dyn BackoffSleeper>,
state: Arc<dyn FaultStateStore>,
delivery_mode: ChunkDeliveryMode,
) -> Result<Self, FaultPolicyError>
pub fn new( policy: FaultPolicy, sleeper: Arc<dyn BackoffSleeper>, state: Arc<dyn FaultStateStore>, delivery_mode: ChunkDeliveryMode, ) -> Result<Self, FaultPolicyError>
Validates and installs the fault-tolerance capability.
§Errors
Returns crate::FaultPolicyError::CommitSafeSkipUnsupported when the
policy accepts a commit-safe skip that the declared delivery mode cannot
commit atomically.
Sourcepub fn policy(&self) -> &FaultPolicy
pub fn policy(&self) -> &FaultPolicy
Borrows the validated step policy.
Sourcepub fn sleeper(&self) -> &dyn BackoffSleeper
pub fn sleeper(&self) -> &dyn BackoffSleeper
Borrows the injected monotonic sleeper.
Sourcepub fn state(&self) -> &dyn FaultStateStore
pub fn state(&self) -> &dyn FaultStateStore
Borrows the reservation store.
Sourcepub const fn delivery_mode(&self) -> ChunkDeliveryMode
pub const fn delivery_mode(&self) -> ChunkDeliveryMode
Returns the delivery mode declared for this step.
Trait Implementations§
Source§impl Clone for FaultRuntime
impl Clone for FaultRuntime
Source§fn clone(&self) -> FaultRuntime
fn clone(&self) -> FaultRuntime
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for FaultRuntime
impl !UnwindSafe for FaultRuntime
impl Freeze for FaultRuntime
impl Send for FaultRuntime
impl Sync for FaultRuntime
impl Unpin for FaultRuntime
impl UnsafeUnpin for FaultRuntime
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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 more