feat(gateway): add /shard_status endpoint

This commit is contained in:
alyssa 2025-05-24 12:23:19 +00:00
parent e2acaf93be
commit b5f18106e1
3 changed files with 51 additions and 20 deletions

View file

@ -14,6 +14,7 @@ use crate::{
discord::{
cache::{dm_channel, DiscordCache, DM_PERMISSIONS},
gateway::cluster_config,
shard_state::ShardStateManager,
},
event_awaiter::{AwaitEventRequest, EventAwaiter},
};
@ -25,7 +26,7 @@ fn status_code(code: StatusCode, body: String) -> Response {
// this function is manually formatted for easier legibility of route_services
#[rustfmt::skip]
pub async fn run_server(cache: Arc<DiscordCache>, runtime_config: Arc<RuntimeConfig>, awaiter: Arc<EventAwaiter>) -> anyhow::Result<()> {
pub async fn run_server(cache: Arc<DiscordCache>, shard_state: Arc<ShardStateManager>, runtime_config: Arc<RuntimeConfig>, awaiter: Arc<EventAwaiter>) -> anyhow::Result<()> {
// hacky fix for `move`
let runtime_config_for_post = runtime_config.clone();
let runtime_config_for_delete = runtime_config.clone();
@ -211,6 +212,10 @@ pub async fn run_server(cache: Arc<DiscordCache>, runtime_config: Arc<RuntimeCon
status_code(StatusCode::NO_CONTENT, "".to_string())
}))
.route("/shard_status", get(|| async move {
status_code(StatusCode::FOUND, to_string(&shard_state.get().await).unwrap())
}))
.layer(axum::middleware::from_fn(crate::logger::logger))
.with_state(cache);