pub fn is_pool_ready(pool: &Mutex<BrowserPool>) -> Result<bool, PdfServiceError>Expand description
Check if the browser pool is ready to handle requests.
Returns true if the pool has available browsers or capacity to create
new ones. This is useful for readiness probes in container orchestration.
§Readiness Criteria
The pool is considered “ready” if either:
- There are idle browsers available (
available > 0), OR - There is capacity to create new browsers (
active < max_pool_size)
The pool is “not ready” only when:
- All browsers are in use AND the pool is at maximum capacity
§Arguments
pool- Reference to the mutex-wrapped browser pool
§Returns
Ok(true)- Pool can accept new requestsOk(false)- Pool is at capacity, requests will queueErr(PdfServiceError::PoolLockFailed)- If mutex is poisoned
§Use Cases
§Kubernetes Readiness Probe
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 10§Load Balancer Health Check
When is_pool_ready returns false, the endpoint should return
HTTP 503 Service Unavailable to remove the instance from rotation.
§Examples
§Basic Check
ⓘ
use html2pdf_api::service::is_pool_ready;
if is_pool_ready(&pool)? {
println!("Pool is ready to accept requests");
} else {
println!("Pool is at capacity");
}§Request Gating
ⓘ
async fn handle_request(pool: &Mutex<BrowserPool>, request: PdfFromUrlRequest) -> Result<PdfResponse, Error> {
// Quick capacity check before expensive operation
if !is_pool_ready(pool)? {
return Err(Error::ServiceUnavailable("Pool at capacity, try again later"));
}
// Proceed with PDF generation
generate_pdf_from_url(pool, &request)
}