fix: retry some times before dropping acquired job
This commit is contained in:
parent
c6d4f713ac
commit
053414824a
2 changed files with 15 additions and 5 deletions
|
@ -82,6 +82,9 @@ pub struct SecurityConfig {
|
|||
|
||||
#[serde_inline_default(30)]
|
||||
pub job_expiration_days: u32,
|
||||
|
||||
#[serde_inline_default(100)]
|
||||
pub reinsertion_attempt_limit: u32,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -115,11 +115,18 @@ impl JobDispatcher for Context {
|
|||
if let Err(e) = res {
|
||||
tracing::error!("failed processing job '{}': {e}", job.activity);
|
||||
let active = job.clone().repeat();
|
||||
if let Err(e) = model::job::Entity::insert(active)
|
||||
.exec(_ctx.db())
|
||||
.await
|
||||
{
|
||||
tracing::error!("could not insert back job ({e}), dropping:\n{job:#?}")
|
||||
let mut count = 0;
|
||||
loop {
|
||||
match model::job::Entity::insert(active.clone()).exec(_ctx.db()).await {
|
||||
Err(e) => tracing::error!("could not insert back job '{}': {e}", job.activity),
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue