➕ try sending webhooks from the relay
parent
e05c4fa8bf
commit
b53748b2c4
|
@ -1396,6 +1396,7 @@ dependencies = [
|
|||
"itertools",
|
||||
"ptth_core",
|
||||
"rand",
|
||||
"reqwest",
|
||||
"rmp-serde",
|
||||
"rusty_ulid 1.0.0",
|
||||
"serde",
|
||||
|
|
|
@ -37,3 +37,8 @@ tracing-futures = "0.2.4"
|
|||
tracing-subscriber = "0.2.15"
|
||||
|
||||
ptth_core = { path = "../ptth_core", version = "2.0.0" }
|
||||
|
||||
[dependencies.reqwest]
|
||||
version = "0.11.13"
|
||||
default-features = false
|
||||
features = ["stream", "rustls-tls", "hyper-rustls"]
|
||||
|
|
|
@ -50,6 +50,32 @@ async fn main () -> Result <(), Box <dyn Error>> {
|
|||
let config_path = PathBuf::from ("config/ptth_relay.toml");
|
||||
let config = Config::from_file (&config_path).await?;
|
||||
|
||||
tokio::spawn (async {
|
||||
let webhook_url = std::env::var ("WEBHOOK_URL");
|
||||
|
||||
let client = reqwest::Client::default ();
|
||||
|
||||
let mut interval = tokio::time::interval (std::time::Duration::from_secs (7200));
|
||||
interval.set_missed_tick_behavior (tokio::time::MissedTickBehavior::Skip);
|
||||
|
||||
let mut tick_seq = 0;
|
||||
|
||||
loop {
|
||||
interval.tick ().await;
|
||||
|
||||
if let Ok (webhook_url) = webhook_url.as_ref () {
|
||||
let now = chrono::Utc::now ();
|
||||
|
||||
let j = serde_json::json! ({
|
||||
"text": format! ("PTTH relay sent test webhook message {} at {:?}", tick_seq, now),
|
||||
}).to_string ();
|
||||
|
||||
client.post (webhook_url).body (j).send ().await.ok ();
|
||||
tick_seq += 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
|
||||
|
||||
forced_shutdown.wrap_server (
|
||||
|
|
Loading…
Reference in New Issue