From ad0a295dd1f4615664abe83048e4fd6043155755 Mon Sep 17 00:00:00 2001 From: asonix Date: Wed, 10 Jan 2024 15:06:59 -0600 Subject: [PATCH] jobs-sled: reorganize completion match --- jobs-sled/src/lib.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/jobs-sled/src/lib.rs b/jobs-sled/src/lib.rs index b957837..5821255 100644 --- a/jobs-sled/src/lib.rs +++ b/jobs-sled/src/lib.rs @@ -133,22 +133,20 @@ impl background_jobs_core::Storage for Storage { }; match result { - JobResult::Success => { - // ok - Ok(true) - } + // successful jobs are removed + JobResult::Success => Ok(true), + // Unregistered or Unexecuted jobs are restored as-is JobResult::Unexecuted | JobResult::Unregistered => { - // TODO: handle - Ok(true) + self.insert(job)?; + Ok(false) } - JobResult::Failure => { - if job.prepare_retry() { - self.insert(job)?; - Ok(false) - } else { - Ok(true) - } + // retryable failed jobs are restored + JobResult::Failure if job.prepare_retry() => { + self.insert(job)?; + Ok(false) } + // dead jobs are removed + JobResult::Failure => Ok(true), } } }