try sending webhooks from the relay

main
(on company time) 2022-12-16 09:30:38 -06:00
parent e05c4fa8bf
commit b53748b2c4
3 changed files with 32 additions and 0 deletions

1
Cargo.lock generated
View File

@ -1396,6 +1396,7 @@ dependencies = [
"itertools", "itertools",
"ptth_core", "ptth_core",
"rand", "rand",
"reqwest",
"rmp-serde", "rmp-serde",
"rusty_ulid 1.0.0", "rusty_ulid 1.0.0",
"serde", "serde",

View File

@ -37,3 +37,8 @@ tracing-futures = "0.2.4"
tracing-subscriber = "0.2.15" tracing-subscriber = "0.2.15"
ptth_core = { path = "../ptth_core", version = "2.0.0" } ptth_core = { path = "../ptth_core", version = "2.0.0" }
[dependencies.reqwest]
version = "0.11.13"
default-features = false
features = ["stream", "rustls-tls", "hyper-rustls"]

View File

@ -50,6 +50,32 @@ async fn main () -> Result <(), Box <dyn Error>> {
let config_path = PathBuf::from ("config/ptth_relay.toml"); let config_path = PathBuf::from ("config/ptth_relay.toml");
let config = Config::from_file (&config_path).await?; 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 (); let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
forced_shutdown.wrap_server ( forced_shutdown.wrap_server (