Skip to content

Commit

Permalink
run once every 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Jan 24, 2024
1 parent 370a717 commit 0fbeb1e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use warp::Filter;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mins_between_runs = 5;
let hours_between_detailed_runs = 12;
let last_update = Arc::new(atomic::AtomicI64::new(chrono::Utc::now().timestamp() / 60));
let last_update_clone = Arc::clone(&last_update);

Expand Down Expand Up @@ -89,12 +91,12 @@ async fn main() -> anyhow::Result<()> {
let empty_game_hash: HashMap<String, String> = HashMap::new();
let mut sessions: HashMap<String, HashMap<String, String>> = HashMap::new();
let mut last_ran_detailed = chrono::Utc::now();
let mut last_ran = chrono::Utc::now();
let mut last_ran = chrono::Utc::now() - chrono::Duration::minutes(mins_between_runs);

log::info!("Started");

loop {
let run = last_ran.add(chrono::Duration::minutes(10)) >= chrono::Utc::now();
let run = last_ran.add(chrono::Duration::minutes(mins_between_runs)) <= chrono::Utc::now();
if run {
log::info!("Starting new run");
last_ran = chrono::Utc::now();
Expand Down Expand Up @@ -201,8 +203,9 @@ async fn main() -> anyhow::Result<()> {
}
log::info!("battlelog done");

let run_detailed =
last_ran_detailed.add(chrono::Duration::hours(12)) <= chrono::Utc::now();
let run_detailed = last_ran_detailed
.add(chrono::Duration::hours(hours_between_detailed_runs))
<= chrono::Utc::now();
if run_detailed {
log::info!("Running grpc detailed");
last_ran_detailed = chrono::Utc::now();
Expand Down Expand Up @@ -273,7 +276,7 @@ async fn main() -> anyhow::Result<()> {
} else {
let ten_mins = last_ran + chrono::Duration::minutes(10);
log::info!(
"Waiting {:#?} minutes before running again",
"Waiting {:#?} minutes before next run",
(ten_mins - last_ran).num_minutes()
);
sleep(Duration::from_secs(30)).await;
Expand Down

0 comments on commit 0fbeb1e

Please sign in to comment.