fix: retry some times before dropping acquired job

This commit is contained in:
əlemi 2024-06-06 04:36:16 +02:00
parent c6d4f713ac
commit 053414824a
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 15 additions and 5 deletions

View file

@ -82,6 +82,9 @@ pub struct SecurityConfig {
#[serde_inline_default(30)] #[serde_inline_default(30)]
pub job_expiration_days: u32, pub job_expiration_days: u32,
#[serde_inline_default(100)]
pub reinsertion_attempt_limit: u32,
} }

View file

@ -115,11 +115,18 @@ impl JobDispatcher for Context {
if let Err(e) = res { if let Err(e) = res {
tracing::error!("failed processing job '{}': {e}", job.activity); tracing::error!("failed processing job '{}': {e}", job.activity);
let active = job.clone().repeat(); let active = job.clone().repeat();
if let Err(e) = model::job::Entity::insert(active) let mut count = 0;
.exec(_ctx.db()) loop {
.await match model::job::Entity::insert(active.clone()).exec(_ctx.db()).await {
{ Err(e) => tracing::error!("could not insert back job '{}': {e}", job.activity),
tracing::error!("could not insert back job ({e}), dropping:\n{job:#?}") Ok(_) => break,
}
count += 1;
if count > _ctx.cfg().security.reinsertion_attempt_limit {
tracing::error!("reached job reinsertion limit, dropping {job:#?}");
break;
}
tokio::time::sleep(std::time::Duration::from_secs(poll_interval)).await;
} }
} }
}); });