pub struct Backends { /* private fields */ }
Expand description
Implementations§
Source§impl Backends
impl Backends
Sourcepub fn new(discovery: Box<dyn ServiceDiscovery + Send + Sync + 'static>) -> Self
pub fn new(discovery: Box<dyn ServiceDiscovery + Send + Sync + 'static>) -> Self
Create a new Backends with the given ServiceDiscovery implementation.
The health check method is by default empty.
Sourcepub fn set_health_check(
&mut self,
hc: Box<dyn HealthCheck + Send + Sync + 'static>,
)
pub fn set_health_check( &mut self, hc: Box<dyn HealthCheck + Send + Sync + 'static>, )
Set the health check method. See health_check for the methods provided.
Sourcepub fn ready(&self, backend: &Backend) -> bool
pub fn ready(&self, backend: &Backend) -> bool
Whether a certain Backend is ready to serve traffic.
This function returns true when the backend is both healthy and enabled.
This function returns true when the health check is unset but the backend is enabled.
When the health check is set, this function will return false for the backend
it
doesn’t know.
Sourcepub fn set_enable(&self, backend: &Backend, enabled: bool)
pub fn set_enable(&self, backend: &Backend, enabled: bool)
Manually set if a Backend is ready to serve traffic.
This method does not override the health of the backend. It is meant to be used to stop a backend from accepting traffic when it is still healthy.
This method is noop when the given backend doesn’t exist in the service discovery.
Sourcepub fn get_backend(&self) -> Arc<BTreeSet<Backend>>
pub fn get_backend(&self) -> Arc<BTreeSet<Backend>>
Return the collection of the backends.
Sourcepub async fn update<F>(&self, callback: F) -> Result<()>
pub async fn update<F>(&self, callback: F) -> Result<()>
Call the service discovery method to update the collection of backends.
The callback will be invoked when the new set of backend is different from the current one so that the caller can update the selector accordingly.
Sourcepub async fn run_health_check(&self, parallel: bool)
pub async fn run_health_check(&self, parallel: bool)
Run health check on all backends if it is set.
When parallel: true
, all backends are checked in parallel instead of sequentially