diff --git a/core/lib/queued_job_processor/src/lib.rs b/core/lib/queued_job_processor/src/lib.rs index 2966fba49cac..49ec8b348ee2 100644 --- a/core/lib/queued_job_processor/src/lib.rs +++ b/core/lib/queued_job_processor/src/lib.rs @@ -109,6 +109,16 @@ pub trait JobProcessor: Sync + Send { task: JoinHandle>, ) -> anyhow::Result<()> { let attempts = self.get_job_attempts(&job_id).await?; + let max_attempts = self.max_attempts(); + if attempts == max_attempts { + METRICS.max_attempts_reached[&(Self::SERVICE_NAME, format!("{job_id:?}"))].inc(); + tracing::error!( + "Max attempts ({max_attempts}) reached for {} job {:?}", + Self::SERVICE_NAME, + job_id, + ); + } + let result = loop { tracing::trace!( "Polling {} task with id {:?}. Is finished: {}", @@ -144,15 +154,6 @@ pub trait JobProcessor: Sync + Send { error_message ); - let max_attempts = self.max_attempts(); - if attempts == max_attempts { - METRICS.max_attempts_reached[&(Self::SERVICE_NAME, format!("{job_id:?}"))].inc(); - tracing::error!( - "Max attempts ({max_attempts}) reached for {} job {:?}", - Self::SERVICE_NAME, - job_id, - ); - } self.save_failure(job_id, started_at, error_message).await; Ok(()) }