From c6d4f713acd34f547b5fdb7ed98ac24438807619 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 6 Jun 2024 04:27:49 +0200 Subject: [PATCH] feat: configurable job expiration defaults to 30 days --- upub/core/src/config.rs | 3 +++ upub/core/src/model/job.rs | 4 ---- upub/core/src/traits/process.rs | 2 +- upub/worker/src/dispatcher.rs | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/upub/core/src/config.rs b/upub/core/src/config.rs index ec8e10f..c78a20f 100644 --- a/upub/core/src/config.rs +++ b/upub/core/src/config.rs @@ -79,6 +79,9 @@ pub struct SecurityConfig { #[serde_inline_default(20)] pub thread_crawl_depth: u32, + + #[serde_inline_default(30)] + pub job_expiration_days: u32, } diff --git a/upub/core/src/model/job.rs b/upub/core/src/model/job.rs index ac54d9b..afcf15c 100644 --- a/upub/core/src/model/job.rs +++ b/upub/core/src/model/job.rs @@ -42,10 +42,6 @@ impl Model { } } - pub fn expired(&self) -> bool { - chrono::Utc::now() - self.published > chrono::Duration::days(7) - } - pub fn repeat(self) -> ActiveModel { ActiveModel { internal: sea_orm::ActiveValue::NotSet, diff --git a/upub/core/src/traits/process.rs b/upub/core/src/traits/process.rs index 517d2ad..9ccfd80 100644 --- a/upub/core/src/traits/process.rs +++ b/upub/core/src/traits/process.rs @@ -1,5 +1,5 @@ use apb::{target::Addressed, Activity, Base, Object}; -use sea_orm::{sea_query::Expr, ActiveValue::{NotSet, Set}, ColumnTrait, Condition, DatabaseTransaction, EntityTrait, QueryFilter, QuerySelect, SelectColumns, TransactionTrait}; +use sea_orm::{sea_query::Expr, ActiveValue::{NotSet, Set}, ColumnTrait, Condition, DatabaseTransaction, EntityTrait, QueryFilter, QuerySelect, SelectColumns}; use crate::{ext::{AnyQuery, LoggableError}, model, traits::{fetch::Pull, Addresser, Fetcher, Normalizer}}; #[derive(Debug, thiserror::Error)] diff --git a/upub/worker/src/dispatcher.rs b/upub/worker/src/dispatcher.rs index 23282e2..16d020f 100644 --- a/upub/worker/src/dispatcher.rs +++ b/upub/worker/src/dispatcher.rs @@ -99,7 +99,7 @@ impl JobDispatcher for Context { }, } - if job.expired() { + if chrono::Utc::now() > job.published + chrono::Duration::days(self.cfg().security.job_expiration_days as i64) { tracing::info!("dropping expired job {job:?}"); restart!(now); }