pub trait Resource:
Send
+ Sync
+ 'static {
// Required methods
fn name(&self) -> &str;
fn health_check(&self) -> Result<(), RuntimeError>;
fn shutdown(&self) -> Result<(), RuntimeError>;
}Expand description
A managed external resource that participates in the runtime lifecycle.
Implement this trait on database pools, caches, message brokers, or any long-lived resource that needs health checking and graceful shutdown.
All methods are synchronous. Health checks run via block_in_place on a
background thread. Shutdown runs during runtime teardown before Tokio
shuts down.
Required Methods§
Sourcefn health_check(&self) -> Result<(), RuntimeError>
fn health_check(&self) -> Result<(), RuntimeError>
Check whether the resource is healthy. Called on a background interval.
Sourcefn shutdown(&self) -> Result<(), RuntimeError>
fn shutdown(&self) -> Result<(), RuntimeError>
Graceful shutdown. Called in reverse registration order during teardown.