Struct ocypod::application::RedisManager
source · pub struct RedisManager<'a> { /* private fields */ }
Expand description
Manages queues and jobs within Redis. Contains main public functions that are called by HTTP services.
Internally, uses RedisJob and RedisQueue structs as convenient wrappers around interacting with jobs/queues.
Implementations
sourceimpl<'a> RedisManager<'a>
impl<'a> RedisManager<'a>
sourcepub fn new(conn: &'a Connection) -> Self
pub fn new(conn: &'a Connection) -> Self
Get a new manager that uses given connection.
sourcepub fn create_or_update_queue(
&self,
name: &str,
settings: &Settings
) -> OcyResult<bool>
pub fn create_or_update_queue(
&self,
name: &str,
settings: &Settings
) -> OcyResult<bool>
Create or update a queue in Redis with given name and settings.
Returns true if a new queue was created, or false if an existing queue was updated.
sourcepub fn delete_queue(&self, name: &str) -> OcyResult<bool>
pub fn delete_queue(&self, name: &str) -> OcyResult<bool>
Delete queue with given name from Redis.
Returns true if a queue was deleted, and false if no queue with given name was found.
sourcepub fn delete_job(&self, job_id: u64) -> OcyResult<bool>
pub fn delete_job(&self, job_id: u64) -> OcyResult<bool>
Delete a job with given ID from Redis.
Returns true if a job was found and deleted, false if no job with given ID was found.
sourcepub fn server_info(&self) -> OcyResult<ServerInfo>
pub fn server_info(&self) -> OcyResult<ServerInfo>
Get summary of server and queue data. Currently contains:
- count of each job’s status by queue
- total number of jobs processed and their final status
sourcepub fn job_fields(
&self,
job_id: u64,
fields: Option<&[Field]>
) -> OcyResult<JobMeta>
pub fn job_fields(
&self,
job_id: u64,
fields: Option<&[Field]>
) -> OcyResult<JobMeta>
Get one or more metadata fields from given job ID.
If None
is given as the fields
argument, then get all fields.
sourcepub fn update_job(&self, job_id: u64, update_req: &UpdateRequest) -> OcyResult<()>
pub fn update_job(&self, job_id: u64, update_req: &UpdateRequest) -> OcyResult<()>
Update one or more job metadata fields.
Only following fields can be updated in this way:
- status - used to mark job as completed/failed/cancelled etc.
- output - used to update user provided information related to this job
sourcepub fn update_job_heartbeat(&self, job_id: u64) -> OcyResult<()>
pub fn update_job_heartbeat(&self, job_id: u64) -> OcyResult<()>
Update a job’s last_heartbeat
field with the current date/time.
sourcepub fn job_status(&self, job_id: u64) -> OcyResult<Status>
pub fn job_status(&self, job_id: u64) -> OcyResult<Status>
Get the status
field of given job.
sourcepub fn set_job_status(&self, job_id: u64, status: &Status) -> OcyResult<()>
pub fn set_job_status(&self, job_id: u64, status: &Status) -> OcyResult<()>
Update a job’s status
field to the given status, if an allowed state transition.
Identical to calling update_job
and with Some(status)
provided.
sourcepub fn job_output(&self, job_id: u64) -> OcyResult<Value>
pub fn job_output(&self, job_id: u64) -> OcyResult<Value>
Get the output
field of given job.
sourcepub fn set_job_output(&self, job_id: u64, value: &Value) -> OcyResult<()>
pub fn set_job_output(&self, job_id: u64, value: &Value) -> OcyResult<()>
Update a job’s output
field to the given output data.
Identical to calling update_job
and with Some(output)
provided.
sourcepub fn tagged_job_ids(&self, tag_name: &str) -> OcyResult<Vec<u64>>
pub fn tagged_job_ids(&self, tag_name: &str) -> OcyResult<Vec<u64>>
Get a list of jobs IDs with given tag name.
sourcepub fn queue_names(&self) -> OcyResult<Vec<String>>
pub fn queue_names(&self) -> OcyResult<Vec<String>>
Get list of all queue names.
sourcepub fn queue_settings(&self, queue_name: &str) -> OcyResult<Settings>
pub fn queue_settings(&self, queue_name: &str) -> OcyResult<Settings>
Get given queue’s current settings.
sourcepub fn queue_size(&self, queue_name: &str) -> OcyResult<u64>
pub fn queue_size(&self, queue_name: &str) -> OcyResult<u64>
Get the number of queues jobs in given queue.
sourcepub fn running_queue_size(&self) -> OcyResult<u64>
pub fn running_queue_size(&self) -> OcyResult<u64>
Get total number of running jobs across all queues.
sourcepub fn failed_queue_size(&self) -> OcyResult<u64>
pub fn failed_queue_size(&self) -> OcyResult<u64>
Get total number of failed jobs across all queues.
sourcepub fn ended_queue_size(&self) -> OcyResult<u64>
pub fn ended_queue_size(&self) -> OcyResult<u64>
Get total number of ended jobs across all queues.
sourcepub fn check_job_retries(&self) -> OcyResult<Vec<u64>>
pub fn check_job_retries(&self) -> OcyResult<Vec<u64>>
Check all jobs in the failed queue for retries.
Any which can be retried are re-queued on the queue they were created it.
Any which have no automatic retries remaining are moved to the ended queue.
sourcepub fn check_job_timeouts(&self) -> OcyResult<Vec<u64>>
pub fn check_job_timeouts(&self) -> OcyResult<Vec<u64>>
Check all jobs in the running queue for timeouts.
Any which timeout are moved to the failed queue, where they’ll eventually either be retried, or moved to the ended queue.
sourcepub fn check_job_expiry(&self) -> OcyResult<Vec<u64>>
pub fn check_job_expiry(&self) -> OcyResult<Vec<u64>>
Check all jobs in the ended queue for expiry. Any expired jobs will be entirely removed from the queue system.
sourcepub fn check_db_integrity(&self) -> OcyResult<()>
pub fn check_db_integrity(&self) -> OcyResult<()>
Checks the integrity of Redis DB, e.g. checking for dangling indexes, jobs in invalid states, etc.
Mostly intended for use during development, as it has a non-trivial runtime cost.
sourcepub fn check_ping(&self) -> OcyResult<()>
pub fn check_ping(&self) -> OcyResult<()>
Check connection to Redis using ping command.
sourcepub fn next_queued_job(&self, queue_name: &str) -> OcyResult<Option<Payload>>
pub fn next_queued_job(&self, queue_name: &str) -> OcyResult<Option<Payload>>
Fetch the next job from given queue, if any.
Returns
A job::Payload
if a job is found, or None
if the queue is empty.
sourcepub fn create_job(
&self,
queue_name: &str,
job_req: &CreateRequest
) -> OcyResult<u64>
pub fn create_job(
&self,
queue_name: &str,
job_req: &CreateRequest
) -> OcyResult<u64>
Create a new job on given queue.