Skip to content

Commit

Permalink
Simplify usage of latte's 'connect' function from the 'context' module
Browse files Browse the repository at this point in the history
Before there were 2 separate fn calls in the 'src/main.rs' module:

    let session = context::connect(conf).await?;
    let session = Context::new(session);

With this change we simplify it the way that we will do only one call:

    let session = context::connect(conf).await?;
  • Loading branch information
vponomaryov authored and pkolaczk committed Jun 20, 2024
1 parent c46790f commit 089d24e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,22 @@ fn ssl_context(conf: &&ConnectionConf) -> Result<Option<SslContext>, CassError>
}

/// Configures connection to Cassandra.
pub async fn connect(conf: &ConnectionConf) -> Result<scylla::Session, CassError> {
pub async fn connect(conf: &ConnectionConf) -> Result<Context, CassError> {
let profile = ExecutionProfile::builder()
.consistency(conf.consistency.scylla_consistency())
.request_timeout(Some(Duration::from_secs(60))) // no request timeout
.build();

SessionBuilder::new()
let scylla_session = SessionBuilder::new()
.known_nodes(&conf.addresses)
.pool_size(PoolSize::PerShard(conf.count))
.user(&conf.user, &conf.password)
.ssl_context(ssl_context(&conf)?)
.default_execution_profile_handle(profile.into_handle())
.build()
.await
.map_err(|e| CassError(CassErrorKind::FailedToConnect(conf.addresses.clone(), e)))
.map_err(|e| CassError(CassErrorKind::FailedToConnect(conf.addresses.clone(), e)))?;
Ok(Context::new(scylla_session))
}

pub struct ClusterInfo {
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ fn find_workload(workload: &Path) -> PathBuf {
async fn connect(conf: &ConnectionConf) -> Result<(Context, Option<ClusterInfo>)> {
eprintln!("info: Connecting to {:?}... ", conf.addresses);
let session = context::connect(conf).await?;
let session = Context::new(session);
let cluster_info = session.cluster_info().await?;
eprintln!(
"info: Connected to {} running Cassandra version {}",
Expand Down

0 comments on commit 089d24e

Please sign in to comment.