pub struct Request<T: RequestState> {
pub state: T,
pub data: RequestData,
}Expand description
A request to be processed by the fusillade system.
Uses the typestate pattern to ensure type-safe state transitions.
The generic parameter T represents the current state of the request.
§Example
let pending_request = Request {
state: Pending {},
data: request_data,
};
// Can only call operations valid for Pending stateFields§
§state: TThe current state of the request.
data: RequestDataThe user-supplied request data.
Implementations§
Source§impl Request<Claimed>
impl Request<Claimed>
pub async fn unclaim<S: Storage + ?Sized>( self, storage: &S, ) -> Result<Request<Pending>>
pub async fn cancel<S: Storage + ?Sized>( self, storage: &S, ) -> Result<Request<Canceled>>
pub async fn process<H: HttpClient + 'static, S: Storage>( self, http_client: H, timeout_ms: u64, storage: &S, ) -> Result<Request<Processing>>
Source§impl Request<Failed>
impl Request<Failed>
Sourcepub fn can_retry(
self,
retry_attempt: u32,
config: RetryConfig,
) -> Result<Request<Pending>, Box<Self>>
pub fn can_retry( self, retry_attempt: u32, config: RetryConfig, ) -> Result<Request<Pending>, Box<Self>>
Attempt to retry this failed request.
If retries are available, transitions the request back to Pending with:
- Incremented retry_attempt
- Calculated not_before timestamp for exponential backoff
If no retries remain, returns None and the request stays Failed.
The retry logic considers:
- max_retries: Hard cap on total retry attempts
- stop_before_deadline_ms: Deadline-aware retry (stops before batch expiration)
Source§impl Request<Processing>
impl Request<Processing>
Sourcepub async fn complete<S, F, Fut>(
self,
storage: &S,
should_retry: F,
cancellation: Fut,
) -> Result<RequestCompletionResult>
pub async fn complete<S, F, Fut>( self, storage: &S, should_retry: F, cancellation: Fut, ) -> Result<RequestCompletionResult>
Wait for the HTTP request to complete.
This method awaits the result from the spawned HTTP task and transitions
the request to one of three terminal states: Completed, Failed, or Canceled.
The should_retry predicate determines whether a response should be considered
a failure (and thus eligible for retry) or a success.
The cancellation future allows external cancellation of the request. It should
resolve to a CancellationReason:
CancellationReason::User: User-initiated cancellation (persists Canceled state)CancellationReason::Shutdown: Daemon shutdown (aborts HTTP but doesn’t persist)CancellationReason::Superseded: Request superseded by racing pair (aborts HTTP but doesn’t persist)
Returns:
RequestCompletionResult::Completedif the HTTP request succeededRequestCompletionResult::Failedif the HTTP request failed or should be retriedRequestCompletionResult::Canceledif the request was canceled by userErr(FusilladeError::Shutdown)if the daemon is shutting down or request was superseded
pub async fn cancel<S: Storage + ?Sized>( self, storage: &S, ) -> Result<Request<Canceled>>
Trait Implementations§
Source§impl From<Request<Processing>> for AnyRequest
impl From<Request<Processing>> for AnyRequest
Source§fn from(r: Request<Processing>) -> Self
fn from(r: Request<Processing>) -> Self
Source§impl From<Request<Superseded>> for AnyRequest
impl From<Request<Superseded>> for AnyRequest
Source§fn from(r: Request<Superseded>) -> Self
fn from(r: Request<Superseded>) -> Self
Auto Trait Implementations§
impl<T> Freeze for Request<T>where
T: Freeze,
impl<T> RefUnwindSafe for Request<T>where
T: RefUnwindSafe,
impl<T> Send for Request<T>
impl<T> Sync for Request<T>
impl<T> Unpin for Request<T>where
T: Unpin,
impl<T> UnwindSafe for Request<T>where
T: UnwindSafe,
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
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>
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 more