This commit is contained in:
Tamo 2022-05-19 15:34:23 +02:00
parent 6d221058f1
commit 9dc3b9d910
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69
2 changed files with 12 additions and 2 deletions

View File

@ -57,6 +57,7 @@ platform-dirs = "0.3.0"
rand = "0.8.5" rand = "0.8.5"
rayon = "1.5.1" rayon = "1.5.1"
regex = "1.5.5" regex = "1.5.5"
reqwest = { version = "0.11.9", features = ["rustls-tls"], default-features = false, optional = true }
rustls = "0.20.4" rustls = "0.20.4"
rustls-pemfile = "0.3.0" rustls-pemfile = "0.3.0"
segment = { version = "0.2.0", optional = true } segment = { version = "0.2.0", optional = true }

View File

@ -78,7 +78,15 @@ impl SegmentAnalytics {
let user_id = user_id.unwrap_or_else(|| Uuid::new_v4().to_string()); let user_id = user_id.unwrap_or_else(|| Uuid::new_v4().to_string());
write_user_id(&opt.db_path, &user_id); write_user_id(&opt.db_path, &user_id);
let client = HttpClient::default();
let reqwest_client = reqwest::Client::builder()
.connect_timeout(Duration::new(10, 0))
.build()
// this unwrap can't fail
.unwrap();
// let client = HttpClient::new(reqwest_client, "https://analytics.meilisearch.com/".to_string());
let client = HttpClient::new(reqwest_client, "https://api.segment.io/".to_string());
let user = User::UserId { user_id }; let user = User::UserId { user_id };
let mut batcher = AutoBatcher::new(client, Batcher::new(None), SEGMENT_API_KEY.to_string()); let mut batcher = AutoBatcher::new(client, Batcher::new(None), SEGMENT_API_KEY.to_string());
@ -259,7 +267,7 @@ impl Segment {
} }
async fn run(mut self, meilisearch: MeiliSearch) { async fn run(mut self, meilisearch: MeiliSearch) {
const INTERVAL: Duration = Duration::from_secs(60 * 60); // one hour const INTERVAL: Duration = Duration::from_secs(30); // one hour
// The first batch must be sent after one hour. // The first batch must be sent after one hour.
let mut interval = let mut interval =
tokio::time::interval_at(tokio::time::Instant::now() + INTERVAL, INTERVAL); tokio::time::interval_at(tokio::time::Instant::now() + INTERVAL, INTERVAL);
@ -284,6 +292,7 @@ impl Segment {
} }
async fn tick(&mut self, meilisearch: MeiliSearch) { async fn tick(&mut self, meilisearch: MeiliSearch) {
println!("TRYING TO SEND SOMETHING");
if let Ok(stats) = meilisearch.get_all_stats(&SearchRules::default()).await { if let Ok(stats) = meilisearch.get_all_stats(&SearchRules::default()).await {
let _ = self let _ = self
.batcher .batcher