From e69f3b54a9febcf46c0cd8a63d33caaa317c6e69 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Sun, 14 May 2023 03:30:10 -0400 Subject: [PATCH] add default values --- packages/backend/crates/config/src/data.rs | 50 +++++++++++++++++++--- packages/backend/crates/config/src/lib.rs | 8 +++- packages/backend/src/main.rs | 10 ++--- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/packages/backend/crates/config/src/data.rs b/packages/backend/crates/config/src/data.rs index 8553f21858..4048329e90 100644 --- a/packages/backend/crates/config/src/data.rs +++ b/packages/backend/crates/config/src/data.rs @@ -112,13 +112,20 @@ pub struct Config { #[serde(default)] pub max_caption_length: MaxCommentLength, // pub disable_hsts: bool, - pub cluster_limit: Option, - // pub deliver_job_concurrency: u16, - // pub inbox_job_concurrency: u16, - // pub deliver_job_per_sec: u16, - // pub inbox_job_per_sec: u16, - // pub deliver_job_max_attempts: u16, - // pub inbox_job_max_attempts: u16, + #[serde(default = "cluster_limit_default")] + pub cluster_limit: u16, + #[serde(default = "deliver_job_default")] + pub deliver_job_concurrency: u16, + #[serde(default = "inbox_job_default")] + pub inbox_job_concurrency: u16, + #[serde(default = "deliver_job_default")] + pub deliver_job_per_sec: u16, + #[serde(default = "inbox_job_default")] + pub inbox_job_per_sec: u16, + #[serde(default = "deliver_job_attempts_default")] + pub deliver_job_max_attempts: u16, + #[serde(default = "inbox_job_attempts_default")] + pub inbox_job_max_attempts: u16, // pub outgoing_address_family: IpFamily, // pub syslog: syslog::SyslogConfig, // pub proxy: Option, @@ -182,6 +189,8 @@ pub mod db { /// redis config pub mod redis { + use url::Url; + use super::*; #[derive(Debug, PartialEq, Deserialize)] @@ -196,6 +205,13 @@ pub mod redis { #[serde(default)] pub db: u8, } + + impl From<&RedisConfig> for Url { + fn from(value: &RedisConfig) -> Self { + Url::parse(&format!("redis://{}:{}", value.host.1, value.port)) + .expect("Invalid redis host and port") + } + } } /// sonic search config @@ -270,6 +286,26 @@ impl Default for MaxCommentLength { } } +fn cluster_limit_default() -> u16 { + 1 +} + +fn deliver_job_default() -> u16 { + 128 +} + +fn deliver_job_attempts_default() -> u16 { + 12 +} + +fn inbox_job_default() -> u16 { + 16 +} + +fn inbox_job_attempts_default() -> u16 { + 8 +} + fn true_fn() -> bool { true } diff --git a/packages/backend/crates/config/src/lib.rs b/packages/backend/crates/config/src/lib.rs index ba1c3ec461..b8830480e9 100644 --- a/packages/backend/crates/config/src/lib.rs +++ b/packages/backend/crates/config/src/lib.rs @@ -123,8 +123,14 @@ redis: }, max_note_length: MaxNoteLength(3000), max_caption_length: MaxCommentLength(1500), - cluster_limit: None, + cluster_limit: 1, env: Environment {}, + deliver_job_concurrency: 128, + inbox_job_concurrency: 16, + deliver_job_per_sec: 128, + inbox_job_per_sec: 16, + deliver_job_max_attempts: 12, + inbox_job_max_attempts: 8, } ); } diff --git a/packages/backend/src/main.rs b/packages/backend/src/main.rs index 4daf3c84bd..5d9a9d6a3d 100644 --- a/packages/backend/src/main.rs +++ b/packages/backend/src/main.rs @@ -17,18 +17,14 @@ fn main() -> anyhow::Result<()> { ); // logging - let is_debug = match env::var_os("NODE_ENV") { - None => true, - Some(val) => val != "production", - }; let subscriber = tracing_subscriber::fmt(); - if is_debug { + if is_release!() { + subscriber.with_max_level(tracing::Level::INFO).init(); + } else { subscriber .with_max_level(tracing::Level::DEBUG) .pretty() .init(); - } else { - subscriber.with_max_level(tracing::Level::INFO).init(); } // bootstrap