async fn wait_for_leader_to_be_elected(client: &eventstore::Client) -> eventstore::Result<()> {
    let mut names = names::Generator::default();
    let stream_name = names.next().unwrap();
    let group_name = names.next().unwrap();
    let mut count = 0;

    while count < 50 {
        count += 1;

        debug!(
            "Checking if we are connected to the leader node...{}/50",
            count
        );
        if let Err(e) = client
            .create_persistent_subscription(
                stream_name.as_str(),
                group_name.as_str(),
                &Default::default(),
            )
            .await
        {
            // If that exception happens, it means next time we are using the connection, we will
            // connected to the leader node.
            if let eventstore::Error::NotLeaderException(_) = e {
                tokio::time::sleep(Duration::from_millis(500)).await;
                debug!("Not available retrying...");
                continue;
            }

            // Probably useless considering we made sure to have the admin user ready is by now.
            if let eventstore::Error::AccessDenied = e {
                tokio::time::sleep(Duration::from_millis(500)).await;
                debug!("Not available retrying...");
                continue;
            }

            return Err(e);
        } else {
            debug!("Election cycle is completed!");
            return Ok(());
        }
    }
    Ok(())
}
// This function makes sure that we are connected to the leader node but also assumes that we are using
// the admin credentials. This function is useful in the case where the environment where the cluster
// is not powerful, which leads to executing commands when the cluster might not having elected
// a leader yet.
This function makes sure that we are connected to the leader node but also assumes that we are using
the admin credentials. This function is useful in the case where the environment where the cluster
is not powerful, which leads to executing commands when the cluster might not having elected
a leader yet.
This function makes sure that we are connected to the leader node but also assumes that we are using the admin credentials . This function is useful in the case where the environment where the cluster is not powerful which leads to executing commands when the cluster might not having elected a leader yet .
async fn wait_for_leader_to_be_elected(client: &eventstore::Client) -> eventstore::Result<()> {
    let mut names = names::Generator::default();
    let stream_name = names.next().unwrap();
    let group_name = names.next().unwrap();
    let mut count = 0;
    while count < 50 {
        count += 1;
        debug!(
            "Checking if we are connected to the leader node...{}/50",
            count
        );
        if let Err(e) = client
            .create_persistent_subscription(
                stream_name.as_str(),
                group_name.as_str(),
                &Default::default(),
            )
            .await
        {
            // If that exception happens, it means next time we are using the connection, we will
            // connected to the leader node.
            if let eventstore::Error::NotLeaderException(_) = e {
                tokio::time::sleep(Duration::from_millis(500)).await;
                debug!("Not available retrying...");
                continue;
            }
            // Probably useless considering we made sure to have the admin user ready is by now.
            if let eventstore::Error::AccessDenied = e {
                tokio::time::sleep(Duration::from_millis(500)).await;
                debug!("Not available retrying...");
                continue;
            }
            return Err(e);
        } else {
            debug!("Election cycle is completed!");
            return Ok(());
        }
    }
    Ok(())
}
async fn wait_for_leader_to_be_elected ( client : & eventstore :: Client ) -> eventstore :: Result < ( ) > { let mut names = names :: Generator :: default ( ) ; let stream_name = names . next ( ) . unwrap ( ) ; let group_name = names . next ( ) . unwrap ( ) ; let mut count = 0 ; while count < 50 { count += 1 ; debug ! ( " " count ) ; if let Err ( e ) = client . create_persistent_subscription ( stream_name . as_str ( ) , group_name . as_str ( ) , & Default :: default ( ) , ) . await { // If that exception happens, it means next time we are using the connection, we will // connected to the leader node. if let eventstore :: Error :: NotLeaderException ( _ ) = e { tokio :: time :: sleep ( Duration :: from_millis ( 500 ) ) . await ; debug ! ( " " ) ; continue ; } // Probably useless considering we made sure to have the admin user ready is by now. if let eventstore :: Error :: AccessDenied = e { tokio :: time :: sleep ( Duration :: from_millis ( 500 ) ) . await ; debug ! ( " " ) ; continue ; } return Err ( e ) ; } else { debug ! ( " " ) ; return Ok ( ( ) ) ; } } Ok ( ( ) ) }
This function makes sure that we are connected to the leader node but also assumes that we are using
the admin credentials.
This function makes sure that we are connected to the leader node but also assumes that we are using the admin credentials .
client
&eventstore::Client
client
&eventstore::Client