Skip to content

Commit 8945328

Browse files
checks for posthog availability
1 parent 98fbb53 commit 8945328

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/network/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ edition = "2021"
55

66
[dependencies]
77
pinger = { git = "https://github.com/orf/gping", package = "pinger" }
8+
reqwest.workspace = true

crates/network/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
use reqwest::Client;
2+
use std::time::Duration;
3+
14
pub async fn is_online() -> bool {
2-
let target = "8.8.8.8".to_string();
3-
let interval = std::time::Duration::from_secs(1);
4-
let options = pinger::PingOptions::new(target, interval, None);
5+
let client = Client::builder()
6+
.timeout(Duration::from_secs(8))
7+
.build()
8+
.unwrap();
59

6-
if let Ok(stream) = pinger::ping(options) {
7-
if let Some(message) = stream.into_iter().next() {
8-
match message {
9-
pinger::PingResult::Pong(_, _) => return true,
10-
_ => return false,
11-
}
12-
}
13-
}
1410

15-
false
11+
let url = "https://posthog.com/";
12+
13+
match client.get(url).send().await {
14+
Ok(resp) if resp.status().is_success() => true,
15+
_ => false,
16+
}
1617
}

0 commit comments

Comments
 (0)