Expand description
Tower integration for Firq scheduling.
firq-tower exposes a configurable layer that:
- extracts a tenant key from requests
- enqueues requests through Firq
- supports cancellation before execution turn
- enforces in-flight limits with a semaphore
- maps scheduling rejections to HTTP-friendly errors
§Example (header-style tenant extraction)
use firq_tower::{Firq, TenantKey};
use std::collections::HashMap;
use std::convert::Infallible;
use std::future::Ready;
use std::task::{Context, Poll};
use tower::{Service, ServiceBuilder};
#[derive(Clone)]
struct Request {
headers: HashMap<&'static str, &'static str>,
body: &'static str,
}
#[derive(Clone)]
struct EchoService;
impl Service<Request> for EchoService {
type Response = &'static str;
type Error = Infallible;
type Future = Ready<Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: Request) -> Self::Future {
std::future::ready(Ok(req.body))
}
}
let layer = Firq::new().build(|req: &Request| {
req.headers
.get("x-tenant-id")
.and_then(|raw| raw.parse::<u64>().ok())
.map(TenantKey::from)
.unwrap_or(TenantKey::from(0))
});
let _svc = ServiceBuilder::new().layer(layer).service(EchoService);Re-exports§
pub use firq_async;
Structs§
- Async
Scheduler - Async wrapper around
Scheduler. - Firq
- Builder for configuring and constructing
FirqLayer. - Firq
Http Rejection - Structured HTTP rejection payload produced by the layer.
- Firq
Layer - Tower
Layerimplementation configured with a Firq scheduler. - Firq
Permit - Internal permit payload sent to the background dequeue worker.
- Firq
Service - Tower
Serviceproduced byFirqLayer. - Queue
Time Bucket - Single histogram bucket for queue time metrics.
- Scheduler
- Multi-tenant in-process scheduler with DRR fairness and explicit backpressure.
- Scheduler
Config - Scheduler runtime configuration.
- Scheduler
Stats - Snapshot of scheduler metrics.
- Task
- Enqueued unit of work.
- Task
Handle - Opaque identifier for a pending task.
- Tenant
Count - Tenant counter entry used in top-talker snapshots.
- Tenant
Key - Stable fairness key used to assign work to shards and DRR queues.
Enums§
- Backpressure
Policy - Behavior when enqueue capacity limits are hit.
- Cancel
Result - Result of task cancellation.
- Close
Mode - Scheduler shutdown mode.
- Dequeue
Result - Result of a dequeue attempt.
- Enqueue
Reject Reason - Reason for enqueue rejection.
- Enqueue
Result - Result of an enqueue operation.
- Enqueue
With Handle Result - Result of
enqueue_with_handle. - Firq
Error - Layer/service error type.
- Priority
- Scheduling priority for a task.
Traits§
Functions§
- default_
rejection_ mapper - Default mapping from scheduler rejection reasons to HTTP responses.
Type Aliases§
- Rejection
Mapper - Function used to map enqueue rejections into HTTP-facing errors.