add discord membercount service & endpoint
a background worker is added that sends an approximate member count request every 60 seconds, caches it into memory, and serves the cache on a public endpoint
This commit is contained in:
@@ -1,5 +1,17 @@
|
||||
use axum::{Router, routing::get};
|
||||
use axum::{Router, http::StatusCode, routing::get};
|
||||
|
||||
pub fn init() -> Router {
|
||||
Router::new().route("/", get(async || "root"))
|
||||
Router::new()
|
||||
.route("/", get(async || "root"))
|
||||
.route("/discord/member-count", get(get_member_count))
|
||||
}
|
||||
|
||||
async fn get_member_count() -> (StatusCode, String) {
|
||||
match crate::discordbot::get_member_count().await {
|
||||
Some(count) => (StatusCode::OK, format!("{count}")),
|
||||
None => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
format!("An error occured - could not fetch discord member count."),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user