mod weekly_report; use tokio::time::{sleep, Duration}; use tokio_rusqlite::Connection; use crate::db; use crate::model::config::Config; use crate::model::job::Job; pub async fn start( config: Config, db_conn: Connection, templates: minijinja::Environment<'_>, ) { loop { if db::jobs::should_run(&db_conn, Job::WeeklyReport).await { log::info!("Starting weekly report job"); if weekly_report::send(&config, &db_conn, &templates).await { db::jobs::actualize_last_execution(&db_conn, Job::WeeklyReport) .await; } } if db::jobs::should_run(&db_conn, Job::MonthlyPayment).await { log::info!("Starting monthly payment job"); db::payments::create_monthly_payments(&db_conn).await; db::jobs::actualize_last_execution(&db_conn, Job::MonthlyPayment) .await; } // Sleeping 8 hours sleep(Duration::from_secs(8 * 60 * 60)).await; } }