mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(cron) call the module
This commit is contained in:
5 files changed
+51
-22
No files matched your search
@@ -1,25 +1,22 @@
|
||||
use std::env;
|
||||
|
||||
use dirs::home_dir;
|
||||
|
||||
pub fn task() {
|
||||
// get dir
|
||||
let git_work_dir_path = &env::var("GIT_WORK_DIR").unwrap_or_else(|e| {
|
||||
if let Ok(default_log_path) = env::var("WORK_DIR") {
|
||||
if default_log_path.starts_with('~') {
|
||||
let home_path = home_dir().unwrap_or_else(|| panic!("Cannot find home directory"));
|
||||
home_path
|
||||
.join(default_log_path.strip_prefix("~/").unwrap())
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.expect(
|
||||
"[fatal] failed to parse env `WORK_DIR`, try to use absolute path instead",
|
||||
)
|
||||
} else {
|
||||
default_log_path
|
||||
}
|
||||
} else {
|
||||
panic!("[fatal] failed to parse env `GIT_WORK_DIR`: {}", e);
|
||||
}
|
||||
});
|
||||
// let git_work_dir_path = &env::var("GIT_WORK_DIR").unwrap_or_else(|e| {
|
||||
// if let Ok(default_log_path) = env::var("WORK_DIR") {
|
||||
// if default_log_path.starts_with('~') {
|
||||
// let home_path = home_dir().unwrap_or_else(|| panic!("Cannot find home directory"));
|
||||
// home_path
|
||||
// .join(default_log_path.strip_prefix("~/").unwrap())
|
||||
// .into_os_string()
|
||||
// .into_string()
|
||||
// .expect(
|
||||
// "[fatal] failed to parse env `WORK_DIR`, try to use absolute path instead",
|
||||
// )
|
||||
// } else {
|
||||
// default_log_path
|
||||
// }
|
||||
// } else {
|
||||
// panic!("[fatal] failed to parse env `GIT_WORK_DIR`: {}", e);
|
||||
// }
|
||||
// });
|
||||
println!("check update");
|
||||
}
|
||||
@@ -1 +1,10 @@
|
||||
use crate::scheduler::tasks::basic::BasicTask;
|
||||
use crate::scheduler::tasks::Task;
|
||||
|
||||
pub mod check_update;
|
||||
|
||||
pub fn get_tasks() -> Vec<Box<dyn Task>> {
|
||||
vec![BasicTask::new(check_update::task, "* * * * * *")
|
||||
.unwrap()
|
||||
.to_task()]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
use crate::blog;
|
||||
use crate::scheduler::Scheduler;
|
||||
|
||||
pub fn start() {
|
||||
let scheduler = Scheduler::new();
|
||||
let _ = vec![blog::cron::get_tasks()]
|
||||
.into_iter()
|
||||
.map(|list| scheduler.insert_list(list))
|
||||
.collect::<Vec<_>>();
|
||||
scheduler.start().unwrap()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod cron;
|
||||
mod database;
|
||||
pub mod logger;
|
||||
pub mod server;
|
||||
@@ -22,6 +23,7 @@ pub fn load_env() {
|
||||
}
|
||||
|
||||
pub async fn start() {
|
||||
// connect database
|
||||
let db_pool = match database::init().await {
|
||||
Ok(pool) => {
|
||||
info!("database connection pool initialized");
|
||||
@@ -36,6 +38,12 @@ pub async fn start() {
|
||||
}
|
||||
};
|
||||
|
||||
// schema init
|
||||
|
||||
// load cron task
|
||||
cron::start();
|
||||
|
||||
// api serve
|
||||
match server::start(db_pool).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
|
||||
@@ -157,6 +157,10 @@ impl Scheduler {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
pub fn insert_list(&self, tasks: Vec<Box<dyn Task>>) -> Result<Vec<Uuid>, SchedulerError> {
|
||||
tasks.into_iter().map(|t| self.insert(t)).collect()
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user