pub struct ClusterNode { /* private fields */ }Expand description
Manages cluster membership and leader election via etcd.
Each worker process creates one ClusterNode instance that:
- Registers the worker in the cluster node registry
- Participates in leader election
- Maintains health status via lease keep-alive
Implementations§
Source§impl ClusterNode
impl ClusterNode
Sourcepub fn new(
etcd_endpoints: Vec<String>,
node_id: String,
node_ip: IpAddr,
group_name: String,
ttl: Option<i64>,
) -> Self
pub fn new( etcd_endpoints: Vec<String>, node_id: String, node_ip: IpAddr, group_name: String, ttl: Option<i64>, ) -> Self
Creates a new ClusterNode.
§Arguments
etcd_endpoints- List of etcd endpoints (e.g.,["http://localhost:2379"])node_id- Unique identifier for this nodenode_ip- IP address of this node (used for service discovery)group_name- Logical group name for cluster membershipttl- Lease TTL in seconds (default: 5)
§Panics
Panics if etcd_endpoints is empty or contains invalid URLs.
Sourcepub fn current_health(&self) -> HealthStatus
pub fn current_health(&self) -> HealthStatus
Returns the current health status of the node’s etcd connection.
Sourcepub async fn run(&self, shutdown: &mut Receiver<()>) -> Result<(), ClusterError>
pub async fn run(&self, shutdown: &mut Receiver<()>) -> Result<(), ClusterError>
Starts the node’s main loop.
This method runs indefinitely, maintaining cluster membership and participating in leader election. It automatically reconnects on connection failures.
If a metrics collector and update interval are configured, a background task will periodically update the node’s metrics in etcd.
§Arguments
shutdown- Shutdown signal receiver. When a message is received, the node will gracefully resign leadership and exit.
§Returns
Returns Ok(()) on graceful shutdown, Err if unable to connect to etcd.
Trait Implementations§
Source§impl Clone for ClusterNode
impl Clone for ClusterNode
Source§fn clone(&self) -> ClusterNode
fn clone(&self) -> ClusterNode
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ClusterNode
impl !RefUnwindSafe for ClusterNode
impl Send for ClusterNode
impl Sync for ClusterNode
impl Unpin for ClusterNode
impl !UnwindSafe for ClusterNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request