fix: comments on PR, removing stuff that's not needed
This commit is contained in:
@@ -10,6 +10,8 @@ services:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
|
||||
data-observatory:
|
||||
depends_on:
|
||||
- postgres
|
||||
image: nym-data-observatory:latest
|
||||
build:
|
||||
context: ../
|
||||
|
||||
@@ -5,8 +5,6 @@ use std::str::FromStr;
|
||||
pub(crate) mod models;
|
||||
pub(crate) mod queries;
|
||||
|
||||
pub(crate) const DATABASE_URL_ENV_VAR: &str = "DATABASE_URL";
|
||||
|
||||
static MIGRATOR: Migrator = sqlx::migrate!("./migrations");
|
||||
|
||||
pub(crate) type DbPool = PgPool;
|
||||
@@ -17,7 +15,8 @@ pub(crate) struct Storage {
|
||||
|
||||
impl Storage {
|
||||
pub async fn init(connection_url: Option<String>) -> Result<Self> {
|
||||
let connection_url = connection_url.unwrap();
|
||||
let connection_url =
|
||||
connection_url.ok_or_else(|| anyhow!("Missing the connection url for database!"))?;
|
||||
let connect_options = {
|
||||
let mut connect_options = PgConnectOptions::from_str(&connection_url)?;
|
||||
let connect_options = connect_options.disable_statement_logging();
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
use crate::read_env_var;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Config {
|
||||
http_port: u16,
|
||||
}
|
||||
|
||||
const HTTP_PORT_DEFAULT: u16 = 8000;
|
||||
|
||||
impl Config {
|
||||
pub(crate) fn from_env() -> Self {
|
||||
Self {
|
||||
http_port: read_env_var("HTTP_PORT")
|
||||
.unwrap_or(HTTP_PORT_DEFAULT.to_string())
|
||||
.parse()
|
||||
.unwrap_or(HTTP_PORT_DEFAULT),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn http_port(&self) -> u16 {
|
||||
self.http_port
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
pub(crate) mod api;
|
||||
pub(crate) mod api_docs;
|
||||
pub(crate) mod config;
|
||||
pub(crate) mod error;
|
||||
pub(crate) mod server;
|
||||
pub(crate) mod state;
|
||||
|
||||
@@ -2,8 +2,6 @@ use clap::Parser;
|
||||
use nym_network_defaults::setup_env;
|
||||
use nym_task::signal::wait_for_signal;
|
||||
|
||||
use crate::http::config;
|
||||
|
||||
mod background_task;
|
||||
mod db;
|
||||
mod http;
|
||||
@@ -16,7 +14,7 @@ struct Args {
|
||||
#[arg(long, default_value_t = 8000, env = "NYM_DATA_OBSERVATORY_HTTP_PORT")]
|
||||
http_port: u16,
|
||||
|
||||
/// Path to the environment file
|
||||
/// Path to the environment variables file. If you don't provide one, variables for the mainnet will be used.
|
||||
#[arg(short, long, default_value = None, env = "NYM_DATA_OBSERVATORY_ENV_FILE")]
|
||||
env_file: Option<String>,
|
||||
|
||||
@@ -33,9 +31,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
setup_env(args.env_file); // Defaults to mainnet if empty
|
||||
|
||||
let conf = config::Config::from_env();
|
||||
tracing::debug!("Using config:\n{:?}", conf);
|
||||
|
||||
let storage = db::Storage::init(args.connection_url).await?;
|
||||
let db_pool = storage.pool_owned().await;
|
||||
tokio::spawn(async move {
|
||||
@@ -56,13 +51,3 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// TODO dz move this to common
|
||||
fn read_env_var(env_var: &str) -> anyhow::Result<String> {
|
||||
std::env::var(env_var)
|
||||
.map_err(|_| anyhow::anyhow!("You need to set {}", env_var))
|
||||
.map(|value| {
|
||||
tracing::trace!("{}={}", env_var, value);
|
||||
value
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user