43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
// mod to communicate with api-grub and preproc services
|
|
// using Unix-Socket Client
|
|
|
|
use anyhow::{Error, Result};
|
|
use integr_structs::api::ApiConfig;
|
|
use tokio::time::{sleep, Instant};
|
|
use tokio::net::UnixStream;
|
|
use std::env;
|
|
|
|
enum UnixSocketConsumer {
|
|
ApiGrubber,
|
|
Preproc,
|
|
}
|
|
// to create us-client
|
|
struct UnixSocketClient;
|
|
|
|
impl UnixSocketConsumer {
|
|
pub async fn get_stream_object(&self) -> Result<UnixStream> {
|
|
let socket_file = match self {
|
|
UnixSocketConsumer::ApiGrubber => env::var("API_GRUBBER_SOCKET")?,
|
|
UnixSocketConsumer::Preproc => env::var("PREPROC_SOCKET")?,
|
|
};
|
|
UnixStream::connect(socket_file).await.or_else(|_| Err(Error::msg("Cannot create Unix-Socket client")))
|
|
}
|
|
}
|
|
|
|
async fn check_unix_socket_file(path: &str) -> bool {
|
|
std::path::Path::new(path).exists()
|
|
}
|
|
|
|
#[cfg(tests)]
|
|
mod delivery_unittests {
|
|
use super::*;
|
|
use tokio::test;
|
|
|
|
//
|
|
#[test]
|
|
async fn check_api_unix_socket_client_creation() { assert!(true); }
|
|
|
|
#[test]
|
|
async fn check_preproc_unix_socket_client_creation() { assert!(true); }
|
|
//
|
|
} |