pub struct Request<T>where
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>( self, storage: &S, ) -> Result<Request<Pending>, FusilladeError>
pub async fn cancel<S>( self, storage: &S, ) -> Result<Request<Canceled>, FusilladeError>
pub async fn process<S, Fut>( self, storage: &S, response_fut: Fut, ) -> Result<Request<Processing>, FusilladeError>
Source§impl Request<Failed>
impl Request<Failed>
Sourcepub fn can_retry(
self,
retry_attempt: u32,
config: RetryConfig,
) -> Result<Request<Pending>, Box<Request<Failed>>>
pub fn can_retry( self, retry_attempt: u32, config: RetryConfig, ) -> Result<Request<Pending>, Box<Request<Failed>>>
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, FusilladeError>
pub async fn complete<S, F, Fut>( self, storage: &S, should_retry: F, cancellation: Fut, ) -> Result<RequestCompletionResult, FusilladeError>
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)
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
pub async fn cancel<S>( self, storage: &S, ) -> Result<Request<Canceled>, FusilladeError>
Trait Implementations§
Source§impl From<Request<Processing>> for AnyRequest
impl From<Request<Processing>> for AnyRequest
Source§fn from(r: Request<Processing>) -> AnyRequest
fn from(r: Request<Processing>) -> AnyRequest
Source§impl<T> Serialize for Request<T>where
T: RequestState + Serialize,
impl<T> Serialize for Request<T>where
T: RequestState + Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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> UnsafeUnpin for Request<T>where
T: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more