mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-11 04:16:55 +00:00
centralized config
This commit is contained in:
1 parent
e8e1d95006
commit
375d95ade9
4 files changed
+25
-13
No files matched your search
@@ -1,12 +1,21 @@
|
||||
// ----- Environment Variable Names -----
|
||||
|
||||
const ENV_ENABLE_PAGING: &str = "ENABLE_PAGING";
|
||||
const ENV_ENABLE_PAGING_FOR_500S: &str = "ENABLE_PAGING_FOR_500S";
|
||||
const ENV_ROOTLY_API_KEY: &str = "ROOTLY_API_KEY";
|
||||
const ENV_ROOTLY_NOTIFICATION_TARGET_TYPE: &str = "ROOTLY_NOTIFICATION_TARGET_TYPE";
|
||||
const ENV_ROOTLY_NOTIFICATION_TARGET_ID: &str = "ROOTLY_NOTIFICATION_TARGET_ID";
|
||||
|
||||
// ----- Read Environment Variables -----
|
||||
|
||||
pub fn env_enable_paging_default_false() -> bool {
|
||||
easyenv::get_env_bool_or_default(ENV_ENABLE_PAGING, false)
|
||||
}
|
||||
|
||||
pub fn env_enable_paging_for_500s_default_false() -> bool {
|
||||
easyenv::get_env_bool_or_default(ENV_ENABLE_PAGING_FOR_500S, false)
|
||||
}
|
||||
|
||||
pub fn env_optional_rootly_api_key() -> Option<String> {
|
||||
easyenv::get_env_string_optional(ENV_ROOTLY_API_KEY)
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ use pager::client::pager_builder::PagerBuilder;
|
||||
use pager::worker::pager_worker::PagerWorker;
|
||||
use rootly_client::creds::rootly_api_key::RootlyApiKey;
|
||||
use rootly_config::services::ROOTLY_SERVICE_ID_VIDEO_THUMBNAIL_JOB;
|
||||
use rootly_config::urgencies::{ROOTLY_URGENCY_ID_HIGH, ROOTLY_URGENCY_ID_MEDIUM, ROOTLY_URGENCY_ID_LOW};
|
||||
use rootly_config::urgencies::{ROOTLY_URGENCY_ID_HIGH, ROOTLY_URGENCY_ID_LOW, ROOTLY_URGENCY_ID_MEDIUM};
|
||||
use shared_env_var_config::paging::{env_enable_paging_default_false, env_optional_rootly_api_key, env_optional_rootly_notification_target_id, env_optional_rootly_notification_target_type};
|
||||
|
||||
pub fn build_pager(
|
||||
server_environment: server_environment::ServerEnvironment,
|
||||
hostname: &str,
|
||||
) -> (Pager, PagerWorker) {
|
||||
let is_paging_enabled = shared_env_var_config::paging::env_enable_paging_default_false();
|
||||
let is_paging_enabled = env_enable_paging_default_false();
|
||||
|
||||
info!("Paging enabled: {}", is_paging_enabled);
|
||||
|
||||
@@ -32,7 +33,7 @@ pub fn build_pager(
|
||||
return builder.build_with_worker();
|
||||
}
|
||||
|
||||
let maybe_api_key = shared_env_var_config::paging::env_optional_rootly_api_key();
|
||||
let maybe_api_key = env_optional_rootly_api_key();
|
||||
|
||||
match maybe_api_key {
|
||||
Some(api_key) => {
|
||||
@@ -53,8 +54,8 @@ fn build_rootly_pager(builder: PagerBuilder, api_key: String) -> (Pager, PagerWo
|
||||
.urgency_id_medium(ROOTLY_URGENCY_ID_MEDIUM.to_string())
|
||||
.urgency_id_low(ROOTLY_URGENCY_ID_LOW.to_string());
|
||||
|
||||
let target_type = shared_env_var_config::paging::env_optional_rootly_notification_target_type();
|
||||
let target_id = shared_env_var_config::paging::env_optional_rootly_notification_target_id();
|
||||
let target_type = env_optional_rootly_notification_target_type();
|
||||
let target_id = env_optional_rootly_notification_target_id();
|
||||
|
||||
if let (Some(t_type), Some(t_id)) = (target_type, target_id) {
|
||||
rootly_builder = rootly_builder.notification_target(t_type, t_id);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::state::flags::paging_flags::PagingFlags;
|
||||
use log::{info, warn};
|
||||
use pager::client::pager::Pager;
|
||||
use pager::client::pager_builder::PagerBuilder;
|
||||
use pager::worker::pager_worker::PagerWorker;
|
||||
use rootly_client::creds::rootly_api_key::RootlyApiKey;
|
||||
use rootly_config::services::ROOTLY_SERVICE_ID_STORYTELLER_WEB;
|
||||
use rootly_config::urgencies::{ROOTLY_URGENCY_ID_HIGH, ROOTLY_URGENCY_ID_MEDIUM, ROOTLY_URGENCY_ID_LOW};
|
||||
|
||||
use crate::state::flags::paging_flags::PagingFlags;
|
||||
use rootly_config::urgencies::{ROOTLY_URGENCY_ID_HIGH, ROOTLY_URGENCY_ID_LOW, ROOTLY_URGENCY_ID_MEDIUM};
|
||||
use shared_env_var_config::paging::{env_optional_rootly_api_key, env_optional_rootly_notification_target_id, env_optional_rootly_notification_target_type};
|
||||
|
||||
pub fn build_pager(
|
||||
server_environment: server_environment::ServerEnvironment,
|
||||
@@ -35,7 +35,7 @@ pub fn build_pager(
|
||||
return (pager, worker, paging_flags);
|
||||
}
|
||||
|
||||
let maybe_api_key = shared_env_var_config::paging::env_optional_rootly_api_key();
|
||||
let maybe_api_key = env_optional_rootly_api_key();
|
||||
|
||||
let (pager, worker) = match maybe_api_key {
|
||||
Some(api_key) => {
|
||||
@@ -58,8 +58,8 @@ fn build_rootly_pager(builder: PagerBuilder, api_key: String) -> (Pager, PagerWo
|
||||
.urgency_id_medium(ROOTLY_URGENCY_ID_MEDIUM.to_string())
|
||||
.urgency_id_low(ROOTLY_URGENCY_ID_LOW.to_string());
|
||||
|
||||
let target_type = shared_env_var_config::paging::env_optional_rootly_notification_target_type();
|
||||
let target_id = shared_env_var_config::paging::env_optional_rootly_notification_target_id();
|
||||
let target_type = env_optional_rootly_notification_target_type();
|
||||
let target_id = env_optional_rootly_notification_target_id();
|
||||
|
||||
if let (Some(t_type), Some(t_id)) = (target_type, target_id) {
|
||||
rootly_builder = rootly_builder.notification_target(t_type, t_id);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use shared_env_var_config::paging::{env_enable_paging_default_false, env_enable_paging_for_500s_default_false};
|
||||
|
||||
/// Flags controlling the pager system.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PagingFlags {
|
||||
@@ -14,8 +16,8 @@ pub struct PagingFlags {
|
||||
impl PagingFlags {
|
||||
pub fn from_env() -> Self {
|
||||
Self {
|
||||
is_paging_enabled: easyenv::get_env_bool_or_default("ENABLE_PAGING", false),
|
||||
is_paging_for_500s_enabled: easyenv::get_env_bool_or_default("ENABLE_PAGING_FOR_500S", false),
|
||||
is_paging_enabled: env_enable_paging_default_false(),
|
||||
is_paging_for_500s_enabled: env_enable_paging_for_500s_default_false(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user