Skip to content

Commit

Permalink
Merge branch 'feature/timeout_key'
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-at-startupmedia committed Oct 27, 2021
2 parents 9366a21 + 0c72b29 commit ed9ca25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/application/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,23 @@ impl RedisJob {
let mut pipe = redis::pipe();
let pipe_ref = pipe.atomic();
match self.status(conn).await {
Ok(job::Status::Failed) | Ok(job::Status::TimedOut) => {
Ok(job::Status::Failed) => {
let result: Option<()> = pipe_ref
.lrem(keys::FAILED_KEY, 1, self.id)
.rpush(keys::ENDED_KEY, self.id)
.query_async(conn)
.await?;
result.map(|_| true)
}
Ok(job::Status::TimedOut) => {
let result: Option<()> = pipe_ref
.lrem(keys::FAILED_KEY, 1, self.id)
.rpush(keys::TIMEDOUT_KEY, self.id)
.rpush(keys::ENDED_KEY, self.id)
.query_async(conn)
.await?;
result.map(|_| true)
}
Ok(_) => Some(false), // jobs status already changed
Err(OcyError::NoSuchJob(_)) => Some(false), // job already deleted
Err(err) => return Err(err),
Expand Down
3 changes: 3 additions & 0 deletions src/application/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub const RUNNING_KEY: &str = "ocypod:running";
/// queue. Jobs in this queue are monitored for retries.
pub const FAILED_KEY: &str = "ocypod:failed";

/// Redis key for the timedout job list. Jobs that have timed out and no longer monitored for retries.
pub const TIMEDOUT_KEY: &str = "ocypod:timedout";

/// Redis key for the ended job list. Jobs are moved here then they have either successfully completed,
/// or failed/timed out with no remaining retries to attempted. Jobs in this queue are monitored for expiry.
pub const ENDED_KEY: &str = "ocypod:ended";
Expand Down

0 comments on commit ed9ca25

Please sign in to comment.