fix(cron::update) fix several errors

This commit is contained in:
lumither committed 2024-11-27 04:00:38 -08:00
1 parent bacaea80a3
commit cbc831bb70
4 files changed
+27 -8

No files matched your search

@@ -295,10 +295,28 @@ $$ LANGUAGE plpgsql;
pub async fn index_file(path: &Path, db_conn: &Pool<Postgres>) -> Result<(), Box<dyn Error>> {
let md_file = MdFile::from_file(path)?;
base(db_conn, &md_file).await?;
tag(db_conn, &md_file).await?;
meta(db_conn, &md_file).await?;
hash(db_conn, &md_file).await?;
async fn trail(db_conn: &Pool<Postgres>, md_file: &MdFile) -> Result<(), PostIdxError> {
base(db_conn, md_file).await?;
tag(db_conn, md_file).await?;
meta(db_conn, md_file).await?;
hash(db_conn, md_file).await.map(|_| ())
}
let mut cnt = 5;
while let Err(e) = trail(db_conn, &md_file).await {
match e {
PostIdxError::DBWriteFailure { .. } => {
cnt -= 1;
}
PostIdxError::DBReadFailure { .. } => {
cnt -= 1;
}
_ => return Err(e.into()),
}
if cnt <= 0 {
return Err(e.into());
}
}
info!("indexed markdown file: {}", path.display());
Ok(())
@@ -111,7 +111,9 @@ pub fn task(db_connection: &Pool<Postgres>) {
}
}
} else if let Some(path) = &update.new_path {
if path.extension().is_some_and(|ext| ext == "md") {
if path.components().any(|comp| comp.as_os_str() == "posts")
&& path.extension().is_some_and(|ext| ext == "md")
{
update_md.push(path.to_path_buf());
}
}
@@ -132,7 +134,7 @@ pub fn task(db_connection: &Pool<Postgres>) {
match Repository::clone(&git_url, &git_work_dir) {
Ok(_repo) => {
// full repo index
let files = search_md(git_work_dir);
let files = search_md(git_work_dir.join("posts"));
index_files(&files, db_connection);
}
Err(e) => {
+1 -1
View File
@@ -7,7 +7,7 @@ pub mod check_update;
pub fn get_tasks(db_connection: Pool<Postgres>) -> Vec<Box<dyn Task>> {
let db_conn_clone = db_connection.clone();
vec![
BasicTask::new(move || check_update::task(&db_conn_clone), "* * * * * *")
BasicTask::new(move || check_update::task(&db_conn_clone), "0 * * * * *")
.unwrap()
.to_task(),
]
-1
View File
@@ -5,7 +5,6 @@ edition = "2021"
[dependencies]
uuid = { version = "1.10.0", features = ["v4", "fast-rng", "serde"] }
chrono = { version = "0.4.38", features = ["serde", "alloc"] }
serde = { version = "1.0.209", features = ["derive"] }
serde_json = "1.0.128"
regex = "1.10.4"