Expose timeout, status, updated_at

This commit is contained in:
asonix 2020-03-22 14:59:36 -05:00
parent cc2d0fbf0d
commit 17416cd892
2 changed files with 39 additions and 0 deletions

View file

@ -90,6 +90,10 @@ impl NewJobInfo {
&self.queue &self.queue
} }
pub fn timeout(&self) -> i64 {
self.timeout
}
/// Whether this job is ready to be run immediately /// Whether this job is ready to be run immediately
pub fn is_ready(&self) -> bool { pub fn is_ready(&self) -> bool {
self.next_queue.is_none() self.next_queue.is_none()
@ -240,6 +244,16 @@ impl JobInfo {
&& (self.updated_at + Duration::milliseconds(self.timeout)) < now) && (self.updated_at + Duration::milliseconds(self.timeout)) < now)
} }
/// Get the status of the job
pub fn status(&self) -> JobStatus {
self.status.clone()
}
/// The the date of the most recent update
pub fn updated_at(&self) -> DateTime<Utc> {
self.updated_at
}
pub(crate) fn is_in_queue(&self, queue: &str) -> bool { pub(crate) fn is_in_queue(&self, queue: &str) -> bool {
self.queue == queue self.queue == queue
} }

View file

@ -125,6 +125,31 @@ impl JobStatus {
} }
} }
impl std::fmt::Display for JobStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
JobStatus::Pending => write!(f, "Pending"),
JobStatus::Running => write!(f, "Running"),
}
}
}
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, thiserror::Error)]
#[error("Invalid job status")]
pub struct JobStatusError;
impl std::str::FromStr for JobStatus {
type Err = JobStatusError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Pending" => Ok(JobStatus::Pending),
"Running" => Ok(JobStatus::Running),
_ => Err(JobStatusError),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
/// Different styles for retrying jobs /// Different styles for retrying jobs
pub enum Backoff { pub enum Backoff {