wip: modified main entry task (code dump)
This commit is contained in:
parent
845f058568
commit
f758c6c078
@ -1,9 +1,12 @@
|
|||||||
use chrono::{prelude::*, Duration};
|
use chrono::{prelude::*, Duration as ChronoDuration};
|
||||||
// use once_cell::sync::Lazy;
|
// use once_cell::sync::Lazy;
|
||||||
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
|
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
mod config;
|
||||||
mod tasks;
|
mod tasks;
|
||||||
|
mod util;
|
||||||
|
|
||||||
pub struct TaskManager<'a> {
|
pub struct TaskManager<'a> {
|
||||||
pool: Pool<Postgres>,
|
pool: Pool<Postgres>,
|
||||||
@ -45,6 +48,7 @@ async fn main() {
|
|||||||
env::var("DATABASE_URL").expect("Environment variable DATABASE_URL is not found");
|
env::var("DATABASE_URL").expect("Environment variable DATABASE_URL is not found");
|
||||||
let pool = PgPoolOptions::new()
|
let pool = PgPoolOptions::new()
|
||||||
.max_connections(10)
|
.max_connections(10)
|
||||||
|
.acquire_timeout(Duration::from_secs(5))
|
||||||
.connect(&database_url)
|
.connect(&database_url)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to connect to the database");
|
.expect("Failed to connect to the database");
|
||||||
@ -54,7 +58,7 @@ async fn main() {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
manager.scheduler.tick();
|
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();
|
.unwrap();
|
||||||
|
|
||||||
let mut scheduler = job_scheduler::JobScheduler::new();
|
let mut scheduler = job_scheduler::JobScheduler::new();
|
||||||
results
|
results.iter().for_each(|j| {
|
||||||
.iter()
|
scheduler.add(job_scheduler::Job::new(j.schedule.parse().unwrap(), || {
|
||||||
.map(|j| {
|
println!("Registering task - task name: {:?}", j.task_name);
|
||||||
scheduler.add(job_scheduler::Job::new(j.schedule.parse().unwrap(), || {
|
|
||||||
println!("Starting task name: {:?}", j.task_name);
|
|
||||||
|
|
||||||
async {
|
match j.task_id {
|
||||||
match j.task_id {
|
1 => tasks::import_posts::import_posts("/app", &self.pool),
|
||||||
1 => tasks::import_posts::import_posts("/app", &self.pool).await,
|
_ => panic!(),
|
||||||
_ => panic!(),
|
};
|
||||||
}
|
}));
|
||||||
};
|
});
|
||||||
}));
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user