mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-02 08:28:18 +00:00
cleanup
This commit is contained in:
1 parent
58b9604c75
commit
353a67ba28
2 files changed
+15
-36
No files matched your search
@@ -99,19 +99,9 @@ async fn main() -> AnyhowResult<()> {
|
||||
// ==================== Setup all dependencies ==================== //
|
||||
|
||||
let setup = setup_dependencies(&server_hostname).await?;
|
||||
|
||||
let pager_for_health_check = setup.server_state.pager.clone();
|
||||
|
||||
// Destructure to avoid partial-move issues.
|
||||
let server_state = setup.server_state;
|
||||
let pager_worker = setup.pager_worker;
|
||||
let health_check_status_clone = setup.health_check_status_clone;
|
||||
let mysql_pool_for_health_check = setup.mysql_pool_for_health_check;
|
||||
let mysql_pool_for_ip_bans = setup.mysql_pool_for_ip_bans;
|
||||
let mysql_pool_for_model_cache = setup.mysql_pool_for_model_cache;
|
||||
let health_check_interval = setup.health_check_interval;
|
||||
let ip_ban_list_clone = setup.ip_ban_list_clone;
|
||||
let model_token_info_cache_clone = setup.model_token_info_cache_clone;
|
||||
let pager_worker = setup.pager_worker;
|
||||
|
||||
// ==================== Background threads ==================== //
|
||||
|
||||
@@ -125,25 +115,35 @@ async fn main() -> AnyhowResult<()> {
|
||||
|
||||
info!("Spawning DB health checker thread.");
|
||||
|
||||
let health_check_status_clone = server_state.health_check_status.clone();
|
||||
let mysql_pool_clone = server_state.mysql_pool.clone();
|
||||
let pager_clone = server_state.pager.clone();
|
||||
|
||||
tokio_runtime.spawn(async move {
|
||||
db_health_checker_thread(
|
||||
health_check_status_clone,
|
||||
mysql_pool_for_health_check,
|
||||
mysql_pool_clone,
|
||||
health_check_interval,
|
||||
pager_for_health_check,
|
||||
pager_clone,
|
||||
).await;
|
||||
});
|
||||
|
||||
info!("Spawning IP ban polling thread.");
|
||||
|
||||
let ip_ban_list_clone = server_state.ip_ban_list.clone();
|
||||
let mysql_pool_clone = server_state.mysql_pool.clone();
|
||||
|
||||
tokio_runtime.spawn(async {
|
||||
poll_ip_bans(ip_ban_list_clone, mysql_pool_for_ip_bans).await;
|
||||
poll_ip_bans(ip_ban_list_clone, mysql_pool_clone).await;
|
||||
});
|
||||
|
||||
info!("Spawning token info cache polling thread.");
|
||||
|
||||
let model_token_info_cache_clone = server_state.caches.durable.model_token_info.clone();
|
||||
let mysql_pool_clone = server_state.mysql_pool.clone();
|
||||
|
||||
tokio_runtime.spawn(async {
|
||||
poll_model_token_info_thread(model_token_info_cache_clone, mysql_pool_for_model_cache).await;
|
||||
poll_model_token_info_thread(model_token_info_cache_clone, mysql_pool_clone).await;
|
||||
});
|
||||
|
||||
// ==================== Serve ==================== //
|
||||
|
||||
@@ -60,15 +60,7 @@ const ENV_AUDIO_UPLOADS_BUCKET_ROOT: &str = "AUDIO_UPLOADS_BUCKET_ROOT";
|
||||
pub struct SetupResult {
|
||||
pub server_state: ServerState,
|
||||
pub pager_worker: PagerWorker,
|
||||
|
||||
/// Clones needed by background threads.
|
||||
pub health_check_status_clone: HealthCheckStatus,
|
||||
pub mysql_pool_for_health_check: MySqlPool,
|
||||
pub mysql_pool_for_ip_bans: MySqlPool,
|
||||
pub mysql_pool_for_model_cache: MySqlPool,
|
||||
pub health_check_interval: Duration,
|
||||
pub ip_ban_list_clone: actix_helpers::middleware::banned_ip_filter::ip_ban_list::ip_ban_list::IpBanList,
|
||||
pub model_token_info_cache_clone: ModelTokenToInfoCache,
|
||||
}
|
||||
|
||||
pub async fn setup_dependencies(server_hostname: &str) -> AnyhowResult<SetupResult> {
|
||||
@@ -184,7 +176,6 @@ pub async fn setup_dependencies(server_hostname: &str) -> AnyhowResult<SetupResu
|
||||
let static_api_token_set = read_static_api_tokens();
|
||||
|
||||
let ip_ban_list = load_static_container_ip_bans();
|
||||
let ip_ban_list_clone = ip_ban_list.clone();
|
||||
|
||||
let cidr_ban_set = load_cidr_bans();
|
||||
|
||||
@@ -192,14 +183,8 @@ pub async fn setup_dependencies(server_hostname: &str) -> AnyhowResult<SetupResu
|
||||
let ip_address_troll_bans = load_ip_address_troll_bans();
|
||||
|
||||
let model_token_info_cache = ModelTokenToInfoCache::new();
|
||||
let model_token_info_cache_clone = model_token_info_cache.clone();
|
||||
|
||||
let health_check_status = HealthCheckStatus::new();
|
||||
let health_check_status_clone = health_check_status.clone();
|
||||
|
||||
let mysql_pool_for_health_check = pool.clone();
|
||||
let mysql_pool_for_ip_bans = pool.clone();
|
||||
let mysql_pool_for_model_cache = pool.clone();
|
||||
|
||||
let server_environment = ServerEnvironment::from_str(&easyenv::get_env_string_required("SERVER_ENVIRONMENT")?)
|
||||
.ok_or(anyhow!("invalid server environment"))?;
|
||||
@@ -335,13 +320,7 @@ pub async fn setup_dependencies(server_hostname: &str) -> AnyhowResult<SetupResu
|
||||
Ok(SetupResult {
|
||||
server_state,
|
||||
pager_worker,
|
||||
health_check_status_clone,
|
||||
mysql_pool_for_health_check,
|
||||
mysql_pool_for_ip_bans,
|
||||
mysql_pool_for_model_cache,
|
||||
health_check_interval,
|
||||
ip_ban_list_clone,
|
||||
model_token_info_cache_clone,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user