Skip to content

Commit 5bbfc74

Browse files
committed
ref: renamed connection functions
1 parent d0ea118 commit 5bbfc74

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
run: PATH=${{ runner.temp }}/proto/bin:$PATH cargo build
2222
env:
2323
RUST_BACKTRACE: 'full'
24-
- name: Test De/Serialization from/to json
24+
- name: Run Tests
2525
run: PATH=${{ runner.temp }}/proto/bin:$PATH cargo test --features all
2626
env:
2727
RUST_BACKTRACE: 'full'

src/flow_queue/connection.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ pub type FlowQueue = Arc<Mutex<Box<Connection>>>;
66

77
pub type FlowChannel = Arc<Mutex<Box<Channel>>>;
88

9-
pub async fn connect(uri: &str) -> Connection {
10-
match Connection::connect(uri, ConnectionProperties::default()).await {
9+
async fn build_connection(rabbitmq_url: &str) -> Connection {
10+
match Connection::connect(rabbitmq_url, ConnectionProperties::default()).await {
1111
Ok(env) => env,
12-
Err(error) => panic!("Cannot connect to redis instance! Reason: {:?}", error),
12+
Err(error) => panic!("Cannot connect to FlowQueue (RabbitMQ) instance! Reason: {:?}", error),
1313
}
1414
}
1515

16-
pub async fn get_flow_channel(uri: &str) -> FlowChannel {
17-
let connection = connect(uri).await;
16+
pub async fn create_flow_channel_connection(uri: &str) -> FlowChannel {
17+
let connection = build_connection(uri).await;
1818

1919
match connection.create_channel().await {
2020
Ok(channel) => Arc::new(Mutex::new(Box::new(channel))),
@@ -24,18 +24,18 @@ pub async fn get_flow_channel(uri: &str) -> FlowChannel {
2424

2525
#[cfg(test)]
2626
mod tests {
27-
use crate::flow_queue::connection::connect;
2827
use testcontainers::core::{IntoContainerPort, WaitFor};
2928
use testcontainers::runners::AsyncRunner;
3029
use testcontainers::GenericImage;
30+
use crate::flow_queue::connection::build_connection;
3131
use crate::rabbitmq_container_test;
3232

3333
rabbitmq_container_test!(test_rabbitmq_startup, (|url: String| async move {
3434
println!("RabbitMQ started with the url: {}", url);
3535
}));
3636

3737
rabbitmq_container_test!(test_rabbitmq_connection, (|url: String| async move {
38-
connect(&*url).await;
38+
build_connection(&*url).await;
3939
}));
4040

4141
}

src/flow_store/connection.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
use redis::Client;
1+
use std::sync::Arc;
2+
use redis::aio::MultiplexedConnection;
3+
use redis::{Client, RedisResult};
4+
use tokio::sync::Mutex;
25

3-
pub fn build_connection(redis_url: String) -> Client {
6+
pub type FlowStore = Arc<Mutex<Box<MultiplexedConnection>>>;
7+
8+
fn build_connection(redis_url: String) -> Client {
49
match Client::open(redis_url) {
510
Ok(client) => client,
6-
Err(con_error) => panic!("{}", con_error),
11+
Err(con_error) => panic!("Cannot create FlowStore (Redis) connection! Reason: {}", con_error),
712
}
813
}
914

15+
pub async fn create_flow_store_connection(url: String) -> FlowStore {
16+
let client = match build_connection(url).get_multiplexed_async_connection().await {
17+
Ok(connection) => connection,
18+
Err(error) => panic!("Cannot create FlowStore (Redis) connection! Reason: {}", error),
19+
};
20+
21+
Arc::new(Mutex::new(Box::new(client)))
22+
}
23+
24+
1025
#[cfg(test)]
1126
mod tests {
1227
use testcontainers::core::IntoContainerPort;

src/flow_store/service.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
use async_trait::async_trait;
22
use log::{debug, error};
3-
use redis::aio::MultiplexedConnection;
43
use redis::{AsyncCommands, RedisError};
5-
use std::sync::Arc;
6-
use tokio::sync::Mutex;
74
use tucana::sagittarius::{Flow, Flows};
8-
9-
pub type FlowStore = Arc<Mutex<MultiplexedConnection>>;
5+
use crate::flow_store::connection::FlowStore;
106

117
#[derive(Debug)]
128
pub struct FlowStoreError {

0 commit comments

Comments
 (0)