Skip to content

Commit

Permalink
use tokio interval in version check instead of sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas-Heiligenbrunner committed Aug 16, 2024
1 parent c19a728 commit 35fb4e6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions backend/src/scheduler/aur_version_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use crate::db::prelude::Packages;
use anyhow::anyhow;
use aur_rs::{Package, Request};
use log::{error, info, warn};
use sea_orm::ActiveValue::Set;
use sea_orm::{ActiveModelTrait, DatabaseConnection, EntityTrait};
use sea_orm::{ActiveModelTrait, ActiveValue::Set, DatabaseConnection, EntityTrait};
use std::env;
use std::time::Duration;
use tokio::task::JoinHandle;
use tokio::time::sleep;
use tokio::{task::JoinHandle, time};

pub fn start_aur_version_checking(db: DatabaseConnection) -> JoinHandle<()> {
let default_version_check_interval = 3600;
Expand All @@ -17,16 +15,17 @@ pub fn start_aur_version_checking(db: DatabaseConnection) -> JoinHandle<()> {
.unwrap_or(default_version_check_interval);

tokio::spawn(async move {
sleep(Duration::from_secs(10)).await;
let mut interval = time::interval(Duration::from_secs(check_interval));

loop {
interval.tick().await;
info!("performing aur version checks");
match aur_check_versions(db.clone()).await {
Ok(_) => {}
Err(e) => {
error!("Failed to perform aur version check: {e}")
}
}
sleep(Duration::from_secs(check_interval)).await;
}
})
}
Expand Down

0 comments on commit 35fb4e6

Please sign in to comment.