From 799391811c795f0918e0df2b1a1b5fc44f55f89f Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 22 Mar 2020 16:04:49 -0500 Subject: [PATCH] Expose next_queue, add docs --- jobs-core/src/job_info.rs | 10 ++++++++-- jobs-core/src/lib.rs | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/jobs-core/src/job_info.rs b/jobs-core/src/job_info.rs index 06c844a..5617043 100644 --- a/jobs-core/src/job_info.rs +++ b/jobs-core/src/job_info.rs @@ -179,6 +179,7 @@ impl JobInfo { self.id } + /// How long (in milliseconds) before this job is considered failed and can be requeued pub fn timeout(&self) -> i64 { self.timeout } @@ -191,13 +192,18 @@ impl JobInfo { } } + /// If the job is queued to run in the future, when is that + pub fn next_queue(&self) -> Option> { + self.next_queue + } + pub(crate) fn increment(&mut self) -> ShouldStop { self.updated(); self.retry_count += 1; self.max_retries.compare(self.retry_count) } - fn next_queue(&mut self) { + fn set_next_queue(&mut self) { let now = Utc::now(); let next_queue = match self.backoff_strategy { @@ -231,7 +237,7 @@ impl JobInfo { if should_retry { self.pending(); - self.next_queue(); + self.set_next_queue(); } should_retry diff --git a/jobs-core/src/lib.rs b/jobs-core/src/lib.rs index 0879577..4f97057 100644 --- a/jobs-core/src/lib.rs +++ b/jobs-core/src/lib.rs @@ -136,6 +136,7 @@ impl std::fmt::Display for JobStatus { #[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, thiserror::Error)] #[error("Invalid job status")] +/// The error generated when parsing a job's status if it's not 'Pending' or 'Running' pub struct JobStatusError; impl std::str::FromStr for JobStatus {