diff --git a/src/main.rs b/src/main.rs index ae8a364..273fa2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,10 @@ struct Config { #[arg(long = "db", short, env)] database_url: String, + + /// How often to poll the Toggl API for new time entries + #[arg(long, short, env, default_value = "7200")] + poll_period: u64, } pub async fn report( @@ -126,7 +130,11 @@ async fn main() -> Result<()> { Migrator::up(&db, None).await.expect("Failed to migrate"); - tokio::spawn(poll::poll_job(toggl_client.clone(), db.clone())); + tokio::spawn(poll::poll_job( + toggl_client.clone(), + db.clone(), + config.poll_period, + )); // build our application with a route let app = Router::new() diff --git a/src/poll.rs b/src/poll.rs index 931fce4..abeb194 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -5,9 +5,9 @@ use tracing::instrument; use crate::entity::{project, client}; #[tracing::instrument(skip(client, db))] -pub async fn poll_job(client: TogglClient, db: DatabaseConnection) { +pub async fn poll_job(client: TogglClient, db: DatabaseConnection, poll_period: u64) { // Every 2h, poll the Toggl API for new time entries for today to cache them in the database - let period = tokio::time::Duration::from_secs(60 * 60 * 2); + let period = tokio::time::Duration::from_secs(poll_period); loop { tracing::info!("Polling Toggl API");