modified task entrypoint

This commit is contained in:
Wyatt J. Miller 2024-11-27 00:34:28 -05:00
parent 2d00604c6f
commit 66ba89c0b1

View File

@ -1,9 +1,9 @@
use chrono::Utc; use chrono::Utc;
use sqlx::{postgres::PgPoolOptions, Pool, Postgres}; use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
use tasks::import_posts;
use std::env; use std::env;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use tasks::import_posts;
//mod config; //mod config;
mod tasks; mod tasks;
@ -19,15 +19,15 @@ pub struct TaskManager<'a> {
#[derive(Debug, sqlx::FromRow)] #[derive(Debug, sqlx::FromRow)]
pub struct TaskLog { pub struct TaskLog {
log_id: u8, log_id: i32,
task_id: u8, task_id: i32,
created_at: chrono::DateTime<Utc>, created_at: chrono::DateTime<Utc>,
task_status: TaskStatus, task_status: String,
finished_at: Option<chrono::DateTime<Utc>>, finished_at: Option<chrono::DateTime<Utc>>,
} }
#[derive(Debug)] #[derive(Debug)]
enum TaskStatus { pub enum TaskStatus {
Pending(String), Pending(String),
Completed(String), Completed(String),
Failed(String), Failed(String),
@ -88,11 +88,9 @@ impl<'a> TaskManager<'a> {
results.iter().for_each(|r| { results.iter().for_each(|r| {
println!("Registering job: {:?}", r.task_name); println!("Registering job: {:?}", r.task_name);
let job: _ = job_scheduler::Job::new(r.schedule.parse().unwrap(), || { let job: _ = job_scheduler::Job::new(r.schedule.parse().unwrap(), || match r.task_id {
match r.task_id {
1 => import_posts::register(&Arc::new(&self.pool)), 1 => import_posts::register(&Arc::new(&self.pool)),
_ => panic!(), _ => panic!(),
}
}); });
scheduler.add(job); scheduler.add(job);