mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
fix(scheduled_tasks): better error handling
This commit is contained in:
parent
ce8d6ed8d3
commit
d5ecccc485
1 changed files with 12 additions and 5 deletions
|
|
@ -10,6 +10,7 @@ use metrics::gauge;
|
||||||
use num_format::{Locale, ToFormattedString};
|
use num_format::{Locale, ToFormattedString};
|
||||||
use reqwest::ClientBuilder;
|
use reqwest::ClientBuilder;
|
||||||
use sqlx::Executor;
|
use sqlx::Executor;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use crate::AppCtx;
|
use crate::AppCtx;
|
||||||
|
|
||||||
|
|
@ -182,16 +183,23 @@ pub async fn update_stats_api(ctx: AppCtx) -> anyhow::Result<()> {
|
||||||
|
|
||||||
let data = resp.json::<PrometheusResult>().await?;
|
let data = resp.json::<PrometheusResult>().await?;
|
||||||
|
|
||||||
|
let error_handler = || {
|
||||||
|
error!("missing data at {}", $q);
|
||||||
|
};
|
||||||
|
|
||||||
data.data
|
data.data
|
||||||
.result
|
.result
|
||||||
.get(0)
|
.get(0)
|
||||||
.expect("missing data")
|
.ok_or_else(error_handler)
|
||||||
|
.unwrap()
|
||||||
.value
|
.value
|
||||||
.clone()
|
.clone()
|
||||||
.get(1)
|
.get(1)
|
||||||
.expect("missing data")
|
.ok_or_else(error_handler)
|
||||||
|
.unwrap()
|
||||||
.as_str()
|
.as_str()
|
||||||
.expect("invalid data")
|
.ok_or_else(error_handler)
|
||||||
|
.unwrap()
|
||||||
.parse::<$t>()?
|
.parse::<$t>()?
|
||||||
}};
|
}};
|
||||||
($t:ty, $q:expr, $wrap:expr) => {{
|
($t:ty, $q:expr, $wrap:expr) => {{
|
||||||
|
|
@ -259,8 +267,7 @@ pub async fn update_stats_api(ctx: AppCtx) -> anyhow::Result<()> {
|
||||||
.set::<(), &str, String>(
|
.set::<(), &str, String>(
|
||||||
"statsapi",
|
"statsapi",
|
||||||
serde_json::to_string(&data).expect("should not fail"),
|
serde_json::to_string(&data).expect("should not fail"),
|
||||||
// Some(fred::types::Expiration::EX(60)),
|
Some(fred::types::Expiration::EX(60)),
|
||||||
None,
|
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue