diff options
author | Joris | 2025-01-31 22:28:53 +0100 |
---|---|---|
committer | Joris | 2025-01-31 22:28:53 +0100 |
commit | 0adf5a093494bdb7f5d5c0f12913133e333ddfad (patch) | |
tree | ada6df0f3480647bec99429819f1bfffd36194ce /src/jobs | |
parent | 24eeb54a6b7159964e8887ade7fa5173b50feb3a (diff) |
Migrate to tokio_rusqlite
Diffstat (limited to 'src/jobs')
-rw-r--r-- | src/jobs/mod.rs | 16 | ||||
-rw-r--r-- | src/jobs/weekly_report.rs | 22 |
2 files changed, 19 insertions, 19 deletions
diff --git a/src/jobs/mod.rs b/src/jobs/mod.rs index a718d93..3bfca71 100644 --- a/src/jobs/mod.rs +++ b/src/jobs/mod.rs @@ -1,7 +1,7 @@ mod weekly_report; -use sqlx::sqlite::SqlitePool; use tokio::time::{sleep, Duration}; +use tokio_rusqlite::Connection; use crate::db; use crate::model::config::Config; @@ -9,21 +9,21 @@ use crate::model::job::Job; pub async fn start( config: Config, - pool: SqlitePool, + db_conn: Connection, templates: minijinja::Environment<'_>, ) { loop { - if db::jobs::should_run(&pool, Job::WeeklyReport).await { + if db::jobs::should_run(&db_conn, Job::WeeklyReport).await { log::info!("Starting weekly report job"); - if weekly_report::send(&config, &pool, &templates).await { - db::jobs::actualize_last_execution(&pool, Job::WeeklyReport) + if weekly_report::send(&config, &db_conn, &templates).await { + db::jobs::actualize_last_execution(&db_conn, Job::WeeklyReport) .await; } } - if db::jobs::should_run(&pool, Job::MonthlyPayment).await { + if db::jobs::should_run(&db_conn, Job::MonthlyPayment).await { log::info!("Starting monthly payment job"); - db::payments::create_monthly_payments(&pool).await; - db::jobs::actualize_last_execution(&pool, Job::MonthlyPayment) + db::payments::create_monthly_payments(&db_conn).await; + db::jobs::actualize_last_execution(&db_conn, Job::MonthlyPayment) .await; } // Sleeping 8 hours diff --git a/src/jobs/weekly_report.rs b/src/jobs/weekly_report.rs index 5058c52..a91a3fb 100644 --- a/src/jobs/weekly_report.rs +++ b/src/jobs/weekly_report.rs @@ -1,5 +1,5 @@ -use sqlx::sqlite::SqlitePool; use std::collections::HashMap; +use tokio_rusqlite::Connection; use crate::db; use crate::mail; @@ -8,12 +8,12 @@ use crate::payer; pub async fn send( config: &Config, - pool: &SqlitePool, + db_conn: &Connection, env: &minijinja::Environment<'_>, ) -> bool { - match get_weekly_report(pool, env).await { + match get_weekly_report(db_conn, env).await { Ok(report) => { - let users = db::users::list(pool).await; + let users = db::users::list(db_conn).await; mail::send( config, users @@ -39,21 +39,21 @@ pub async fn send( } async fn get_weekly_report( - pool: &SqlitePool, + db_conn: &Connection, env: &minijinja::Environment<'_>, ) -> Result<String, minijinja::Error> { - let users = db::users::list(pool).await; - let incomes_from = db::incomes::defined_for_all(pool).await; + let users = db::users::list(db_conn).await; + let incomes_from = db::incomes::defined_for_all(db_conn).await; let user_incomes = match incomes_from { - Some(from) => db::incomes::cumulative(pool, from).await, + Some(from) => db::incomes::cumulative(db_conn, from).await, None => HashMap::new(), }; - let user_payments = db::payments::repartition(pool).await; + let user_payments = db::payments::repartition(db_conn).await; let exceeding_payers = payer::exceeding(&users, &user_incomes, &user_payments); - let last_week_payments = db::payments::last_week(pool).await; - let last_week_incomes = db::incomes::last_week(pool).await; + let last_week_payments = db::payments::last_week(db_conn).await; + let last_week_incomes = db::incomes::last_week(db_conn).await; let template = env.get_template("report/report.j2")?; template.render(minijinja::context!( |