fix: deserialize scheduled_at_ms as string or number (postgres bigint serializes as string)
This commit is contained in:
parent
c5eb514990
commit
980261632e
|
|
@ -1,7 +1,19 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
|
||||
// Postgres BIGINT sometimes comes back as a JSON string — handle both
|
||||
fn deserialize_ms<'de, D: Deserializer<'de>>(d: D) -> Result<Option<i64>, D::Error> {
|
||||
use serde::de::Error;
|
||||
let v: Option<serde_json::Value> = Option::deserialize(d)?;
|
||||
match v {
|
||||
None => Ok(None),
|
||||
Some(serde_json::Value::Number(n)) => Ok(n.as_i64()),
|
||||
Some(serde_json::Value::String(s)) => s.parse::<i64>().map(Some).map_err(D::Error::custom),
|
||||
Some(other) => Err(D::Error::custom(format!("unexpected type for scheduled_at_ms: {other}"))),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Monitor {
|
||||
pub id: String,
|
||||
|
|
@ -13,6 +25,7 @@ pub struct Monitor {
|
|||
pub interval_s: i64,
|
||||
pub query: Option<Value>,
|
||||
pub scheduled_at: Option<String>, // ISO string for backward compat in PingResult
|
||||
#[serde(deserialize_with = "deserialize_ms")]
|
||||
pub scheduled_at_ms: Option<i64>, // unix ms from API for precise scheduling
|
||||
pub regions: Option<Vec<String>>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue