wip: modified main entry task (code dump)

This commit is contained in:
Wyatt J. Miller 2024-09-24 20:29:22 -04:00
parent 845f058568
commit f758c6c078

View File

@ -1,9 +1,12 @@
use chrono::{prelude::*, Duration};
use chrono::{prelude::*, Duration as ChronoDuration};
// use once_cell::sync::Lazy;
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
use std::env;
use std::time::Duration;
mod config;
mod tasks;
mod util;
pub struct TaskManager<'a> {
pool: Pool<Postgres>,
@ -45,6 +48,7 @@ async fn main() {
env::var("DATABASE_URL").expect("Environment variable DATABASE_URL is not found");
let pool = PgPoolOptions::new()
.max_connections(10)
.acquire_timeout(Duration::from_secs(5))
.connect(&database_url)
.await
.expect("Failed to connect to the database");
@ -54,7 +58,7 @@ async fn main() {
loop {
manager.scheduler.tick();
std::thread::sleep(std::time::Duration::from_millis(1000));
std::thread::sleep(std::time::Duration::from_millis(500));
}
}
@ -77,20 +81,15 @@ impl<'a> TaskManager<'a> {
.unwrap();
let mut scheduler = job_scheduler::JobScheduler::new();
results
.iter()
.map(|j| {
scheduler.add(job_scheduler::Job::new(j.schedule.parse().unwrap(), || {
println!("Starting task name: {:?}", j.task_name);
results.iter().for_each(|j| {
scheduler.add(job_scheduler::Job::new(j.schedule.parse().unwrap(), || {
println!("Registering task - task name: {:?}", j.task_name);
async {
match j.task_id {
1 => tasks::import_posts::import_posts("/app", &self.pool).await,
_ => panic!(),
}
};
}));
})
.collect::<Vec<_>>();
match j.task_id {
1 => tasks::import_posts::import_posts("/app", &self.pool),
_ => panic!(),
};
}));
});
}
}