Skip to content

Commit 21a624d

Browse files
committed
feat: run every 5 mins
1 parent 1492cda commit 21a624d

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

aw-firebase-sync/src/main.rs

+34-23
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ use dirs::config_dir;
44
use reqwest;
55
use serde_json::{json, Value};
66
use serde_yaml;
7+
use std::env;
78
use std::fs::{DirBuilder, File};
89
use std::io::prelude::*;
9-
use std::env;
10+
use tracing::info;
11+
use tracing_subscriber;
1012

1113
#[tokio::main]
1214
async fn main() -> Result<(), Box<dyn std::error::Error>> {
13-
15+
tracing_subscriber::fmt::init();
1416
let args: Vec<String> = env::args().collect();
1517
let mut port: u16 = 5600;
1618
if args.len() > 1 {
@@ -29,10 +31,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2931
}
3032
}
3133
let aw_client = AwClient::new("localhost", port, "aw-firebase-sync").unwrap();
32-
#[allow(deprecated)]
33-
let start = Utc::now().date().and_hms_opt(0, 0, 0).unwrap() - chrono::Duration::days(7);
34-
#[allow(deprecated)]
35-
let end = Utc::now().date().and_hms_opt(0, 0, 0).unwrap() + chrono::Duration::days(1);
3634

3735
let path = config_dir()
3836
.map(|mut path| {
@@ -76,26 +74,39 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7674
events = filter_keyvals(events, \"$category\", [[\"Work\"]]);
7775
RETURN = events;
7876
";
79-
let timeperiods = vec![(start, end)];
80-
let query_result = aw_client.query(&query, timeperiods).await.expect("Failed to query data");
81-
let query_data = serde_json::to_string(&query_result[0]).expect("Failed to serialize query data");
8277

8378
let firebase_url = "https://us-central1-aw-mockup.cloudfunctions.net/uploadData";
8479
// let firebase_url = "http://localhost:5001/aw-mockup/us-central1/uploadData";
8580

86-
let payload = json!({
87-
"apiKey": apikey,
88-
"data": query_data
89-
});
90-
9181
let firebase_client = reqwest::Client::new();
92-
let response = firebase_client
93-
.post(firebase_url)
94-
.json(&payload)
95-
.send()
96-
.await?
97-
.json::<Value>()
98-
.await?;
99-
println!("Response: {:?}", response);
100-
Ok(())
82+
83+
loop {
84+
#[allow(deprecated)]
85+
let start =
86+
Utc::now().date().and_hms_opt(0, 0, 0).unwrap() - chrono::Duration::seconds(300);
87+
#[allow(deprecated)]
88+
let end = Utc::now().date().and_hms_opt(0, 0, 0).unwrap();
89+
let timeperiods = vec![(start, end)];
90+
91+
let query_result = aw_client
92+
.query(&query, timeperiods)
93+
.await
94+
.expect("Failed to query data");
95+
let query_data =
96+
serde_json::to_string(&query_result[0]).expect("Failed to serialize query data");
97+
let payload = json!({
98+
"apiKey": apikey,
99+
"data": query_data
100+
});
101+
let response = firebase_client
102+
.post(firebase_url)
103+
.json(&payload)
104+
.send()
105+
.await?
106+
.json::<Value>()
107+
.await?;
108+
info!("Response: {:?}", response);
109+
std::thread::sleep(std::time::Duration::from_secs(300));
110+
}
111+
// Ok(())
101112
}

0 commit comments

Comments
 (0)