fix healthchecks
This commit is contained in:
parent
7d7dd0d64c
commit
f5f96e35d8
1 changed files with 39 additions and 10 deletions
|
@ -1,6 +1,8 @@
|
||||||
use async_graphql::{Enum, Object};
|
use std::any::Any;
|
||||||
|
|
||||||
|
use async_graphql::{Context, Enum, Object};
|
||||||
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
|
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
|
||||||
use redis::pipe;
|
use redis::{aio::MultiplexedConnection, pipe};
|
||||||
|
|
||||||
pub async fn get_health(
|
pub async fn get_health(
|
||||||
Extension(mut redis): Extension<redis::aio::MultiplexedConnection>,
|
Extension(mut redis): Extension<redis::aio::MultiplexedConnection>,
|
||||||
|
@ -59,29 +61,56 @@ enum WebsocketState {
|
||||||
|
|
||||||
pub struct Health {}
|
pub struct Health {}
|
||||||
|
|
||||||
|
impl Health {
|
||||||
|
async fn get_health<'ctx>(&self, ctx: &Context<'ctx>, pair: &str) -> WebsocketState {
|
||||||
|
let mut con = ctx.data::<MultiplexedConnection>().unwrap().to_owned();
|
||||||
|
let (primary, backup): (Option<String>, Option<String>) = pipe()
|
||||||
|
.get(format!("heartbeat:{}:primary", pair))
|
||||||
|
.get(format!("heartbeat:{}:backup", pair))
|
||||||
|
.query_async(&mut con)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
match (primary, backup) {
|
||||||
|
(Some(_), _) => WebsocketState::Primary,
|
||||||
|
(None, Some(_)) => WebsocketState::Backup,
|
||||||
|
_ => WebsocketState::Down,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Reports on the health of Saerro Listening Post
|
/// Reports on the health of Saerro Listening Post
|
||||||
#[Object]
|
#[Object]
|
||||||
impl Health {
|
impl Health {
|
||||||
/// Did a ping to Redis (our main datastore) succeed?
|
/// Did a ping to Redis (our main datastore) succeed?
|
||||||
async fn redis(&self) -> UpDown {
|
async fn redis<'ctx>(&self, ctx: &Context<'ctx>) -> UpDown {
|
||||||
|
let mut con = ctx.data::<MultiplexedConnection>().unwrap().to_owned();
|
||||||
|
let ping: String = redis::cmd("PING")
|
||||||
|
.query_async(&mut con)
|
||||||
|
.await
|
||||||
|
.unwrap_or_default();
|
||||||
|
if ping == "PONG" {
|
||||||
UpDown::Up
|
UpDown::Up
|
||||||
|
} else {
|
||||||
|
UpDown::Down
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What is the state of the websocket listener cluster for PC?
|
/// What is the state of the websocket listener cluster for PC?
|
||||||
#[graphql(name = "pc")]
|
#[graphql(name = "pc")]
|
||||||
async fn pc(&self) -> WebsocketState {
|
async fn pc<'ctx>(&self, ctx: &Context<'ctx>) -> WebsocketState {
|
||||||
WebsocketState::Primary
|
self.get_health(ctx, "pc").await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What is the state of the websocket listener cluster for PS4 US?
|
/// What is the state of the websocket listener cluster for PS4 US?
|
||||||
#[graphql(name = "ps4us")]
|
#[graphql(name = "ps4us")]
|
||||||
async fn ps4us(&self) -> WebsocketState {
|
async fn ps4us<'ctx>(&self, ctx: &Context<'ctx>) -> WebsocketState {
|
||||||
WebsocketState::Primary
|
self.get_health(ctx, "ps4us").await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What is the state of the websocket listener cluster for PS4 EU?
|
/// What is the state of the websocket listener cluster for PS4 EU?
|
||||||
#[graphql(name = "ps4eu")]
|
#[graphql(name = "ps4eu")]
|
||||||
async fn ps4eu(&self) -> WebsocketState {
|
async fn ps4eu<'ctx>(&self, ctx: &Context<'ctx>) -> WebsocketState {
|
||||||
WebsocketState::Primary
|
self.get_health(ctx, "ps4eu").await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue