Struct pingora_load_balancing::Backends
source · 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(&self) -> Result<bool>
pub async fn update(&self) -> Result<bool>
Call the service discovery method to update the collection of backends.
Return true when the new collection is different from the current set of backends.
This return value is useful to tell the caller when to rebuild things that are expensive to
update, such as consistent hashing rings.
sourcepub async fn run_health_check(&self, parallel: bool)
pub async fn run_health_check(&self, parallel: bool)
Run health check on all the backend if it is set.
When parallel: true, all the backends are checked in parallel instead of sequentially