From 11052951b74b9ad4b6a9412ae490086235f9154b Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 3 Jan 2021 13:40:40 +0100 Subject: Rewrite in Rust --- src/jobs/jobs.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/jobs/jobs.rs (limited to 'src/jobs/jobs.rs') diff --git a/src/jobs/jobs.rs b/src/jobs/jobs.rs new file mode 100644 index 0000000..3e54624 --- /dev/null +++ b/src/jobs/jobs.rs @@ -0,0 +1,28 @@ +use sqlx::sqlite::SqlitePool; +use tera::Tera; +use tokio::time::{delay_for, Duration}; + +use crate::db; +use crate::jobs::weekly_report; +use crate::model::config::Config; +use crate::model::job::Job; + +pub async fn start(config: Config, pool: SqlitePool, templates: Tera) -> () { + loop { + if db::jobs::should_run(&pool, Job::WeeklyReport).await { + info!("Starting weekly report job"); + if weekly_report::send(&config, &pool, &templates).await { + db::jobs::actualize_last_execution(&pool, Job::WeeklyReport) + .await; + } + } + if db::jobs::should_run(&pool, Job::MonthlyPayment).await { + info!("Starting monthly payment job"); + db::payments::create_monthly_payments(&pool).await; + db::jobs::actualize_last_execution(&pool, Job::MonthlyPayment) + .await; + } + // Sleeping 8 hours + delay_for(Duration::from_secs(8 * 60 * 60)).await; + } +} -- cgit v1.2.3