- update: service port env variable to just be named service_port

This commit is contained in:
2025-03-18 11:57:39 -04:00
parent 8e39c42046
commit 89a1e93dc3
9 changed files with 25 additions and 16 deletions

View File

@@ -4,14 +4,13 @@ use database_service::grpc::database_service::MyDatabaseService;
use database_service::grpc::user_service_server::UserServiceServer;
use dotenv::dotenv;
use sqlx::postgres::PgPoolOptions;
use std::collections::HashMap;
use std::env;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
use tokio::sync::Mutex;
use tonic::transport::Server;
use tracing::{info, Level};
use utils::consul_registration;
use utils::redis_cache::RedisCache;
#[tokio::main]
@@ -25,13 +24,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.init();
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
let port = env::var("DATABASE_SERVICE_PORT").unwrap_or_else(|_| "50052".to_string());
let port = env::var("SERVICE_PORT").unwrap_or_else(|_| "50052".to_string());
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let redis_url = env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1:6379".to_string());
let full_addr = format!("{}:{}", &addr, port);
let address = full_addr.parse().expect("Invalid address");
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
@@ -45,8 +42,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
health_reporter.set_serving::<UserServiceServer<MyDatabaseService>>().await;
// Pass `shared_cache` into services as needed
info!("Database Service running on {}", address);
let address = SocketAddr::new(addr.parse()?, port.parse()?);
tokio::spawn(
Server::builder()
.add_service(health_service)
@@ -54,6 +50,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.add_service(CharacterDbServiceServer::new(my_service))
.serve(address),
);
info!("Database Service running on {}", address);
utils::signal_handler::wait_for_signal().await;
Ok(())