Skip to main content

Queue

Struct Queue 

Source
pub struct Queue { /* private fields */ }
Expand description

A Queue is the main entry point for adding jobs to be processed.

It provides methods for adding single and bulk jobs, and managing queue state (pause, resume, drain, obliterate).

Implementations§

Source§

impl Queue

Source

pub async fn new(name: &str, opts: QueueOptions) -> Result<Self, Error>

Create a new Queue connected to Redis.

Source

pub async fn with_connection( name: &str, conn: RedisConnection, opts: QueueOptions, ) -> Result<Self, Error>

Create a Queue with an existing Redis connection.

Source

pub fn name(&self) -> &str

The queue name.

Source

pub fn keys(&self) -> &QueueKeys

The queue keys helper.

Source

pub fn connection(&self) -> &RedisConnection

The underlying Redis connection.

Source

pub async fn add( &self, name: &str, data: Value, opts: Option<JobOptions>, ) -> Result<Job, Error>

Add a job to the queue.

Source

pub async fn add_bulk( &self, jobs: Vec<(String, Value, Option<JobOptions>)>, ) -> Result<Vec<Job>, Error>

Add multiple jobs to the queue in a single operation.

Jobs are added concurrently over the multiplexed connection for maximum throughput.

Source

pub async fn pause(&self) -> Result<(), Error>

Pause the queue.

Source

pub async fn resume(&self) -> Result<(), Error>

Resume the queue.

Source

pub async fn is_paused(&self) -> Result<bool, Error>

Check if the queue is paused.

Source

pub async fn get_job(&self, job_id: &str) -> Result<Option<Job>, Error>

Get a job by its ID.

Source

pub async fn get_job_counts(&self) -> Result<JobCounts, Error>

Get the counts of jobs in each state.

Source

pub async fn get_ranges( &self, types: &[&str], start: i64, end: i64, asc: bool, ) -> Result<Vec<String>, Error>

Return job IDs for the given states with pagination.

types are state names (e.g. "waiting", "active", "completed"). start/end are zero-based inclusive indices (-1 = last). When asc is true, jobs are returned in ascending (oldest-first) order.

The requested types are sanitized via Queue::sanitize_job_types: an empty slice expands to all states, waiting also queries paused, and duplicate types are removed. Results from all requested states are concatenated and de-duplicated while preserving order.

Source

pub async fn get_jobs( &self, types: &[&str], start: i64, end: i64, asc: bool, ) -> Result<Vec<Job>, Error>

Return the jobs that are in the given states with pagination.

types are state names. An empty slice returns jobs from all states.

Source

pub async fn get_waiting(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>

Return jobs in the waiting (and paused) state.

Source

pub async fn get_waiting_children( &self, start: i64, end: i64, ) -> Result<Vec<Job>, Error>

Return jobs in the waiting-children state (parents with pending children).

Source

pub async fn get_active(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>

Return jobs in the active state.

Source

pub async fn get_delayed(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>

Return jobs in the delayed state.

Source

pub async fn get_prioritized( &self, start: i64, end: i64, ) -> Result<Vec<Job>, Error>

Return jobs in the prioritized state.

Source

pub async fn get_completed( &self, start: i64, end: i64, ) -> Result<Vec<Job>, Error>

Return jobs in the completed state.

Source

pub async fn get_failed(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>

Return jobs in the failed state.

Source

pub async fn get_job_counts_by_types( &self, types: &[&str], ) -> Result<HashMap<String, u64>, Error>

Return the job counts for each provided type, keyed by type name.

An empty types slice returns counts for every queryable state.

Source

pub async fn get_job_count_by_types(&self, types: &[&str]) -> Result<u64, Error>

Return the total number of jobs across the provided types.

Source

pub async fn record_job_counts_metric( &self, types: &[&str], recorder: Option<JobCountRecorder<'_>>, ) -> Result<HashMap<String, u64>, Error>

Return job counts by state, invoking recorder once per (state, count).

Mirrors Node.js Queue.recordJobCountsMetric, which records gauge metrics when telemetry is configured. The Rust port has no built-in telemetry subsystem, so the optional recorder closure is the integration point: pass None to simply retrieve the counts, or supply a closure to forward each state’s count to your metrics backend.

Source

pub async fn count(&self) -> Result<u64, Error>

Return the number of jobs waiting to be processed: this sums waiting, paused, delayed, prioritized and waiting-children.

Source

pub async fn get_counts_per_priority( &self, priorities: &[u64], ) -> Result<HashMap<u64, u64>, Error>

Return the number of jobs per priority for the provided priorities.

Priorities are de-duplicated. The returned map is keyed by priority value.

Source

pub async fn get_completed_count(&self) -> Result<u64, Error>

Return the number of jobs in the completed state.

Source

pub async fn get_failed_count(&self) -> Result<u64, Error>

Return the number of jobs in the failed state.

Source

pub async fn get_delayed_count(&self) -> Result<u64, Error>

Return the number of jobs in the delayed state.

Source

pub async fn get_active_count(&self) -> Result<u64, Error>

Return the number of jobs in the active state.

Source

pub async fn get_prioritized_count(&self) -> Result<u64, Error>

Return the number of jobs in the prioritized state.

Source

pub async fn get_waiting_count(&self) -> Result<u64, Error>

Return the number of jobs in the waiting (and paused) state.

Source

pub async fn get_waiting_children_count(&self) -> Result<u64, Error>

Return the number of jobs in the waiting-children state.

Source

pub async fn get_workers(&self) -> Result<Vec<HashMap<String, String>>, Error>

Return the list of workers currently connected to this queue.

Workers register themselves via CLIENT SETNAME on their blocking connection; this method runs CLIENT LIST and returns the parsed info maps for clients whose name matches this queue. Each map’s name field is set to the queue name and the original client name is preserved in rawname (mirroring Node.js Queue.getWorkers).

Note: some managed Redis providers (e.g. GCP Memorystore) do not support CLIENT SETNAME/CLIENT LIST, in which case this returns an empty list.

Source

pub async fn get_workers_count(&self) -> Result<usize, Error>

Return the number of workers currently connected to this queue.

Source

pub async fn get_meta(&self) -> Result<QueueMeta, Error>

Return the queue’s public metadata (read from the meta hash).

Well-known numeric/boolean fields (concurrency, max, duration, opts.maxLenEvents, paused) are parsed into typed fields; any other entries are preserved in QueueMeta::other. Mirrors Node.js Queue.getMeta.

Source

pub async fn get_version(&self) -> Result<Option<String>, Error>

Return the library version string stored in the meta hash.

The Rust port records bullmq-official:<version> under the library field when the queue is created. Returns None if the field is unset.

Source

pub async fn is_maxed(&self) -> Result<bool, Error>

Return true when the number of active jobs has reached the queue’s global concurrency limit. Returns false when no global concurrency is configured. Mirrors Node.js Queue.isMaxed.

Source

pub async fn export_prometheus_metrics( &self, global_labels: &[(&str, &str)], ) -> Result<String, Error>

Export the queue’s job counts and totals in the Prometheus text exposition format.

Emits a bullmq_job_count gauge per job state plus bullmq_job_completed_total / bullmq_job_failed_total counters sourced from the time-series metrics. global_labels are appended (in order) as extra labels on every series; pass &[] for none. Mirrors Node.js Queue.exportPrometheusMetrics.

Source

pub async fn get_metrics( &self, metric_type: &str, start: i64, end: i64, ) -> Result<Metrics, Error>

Return the time-series metrics for the queue.

metric_type must be "completed" or "failed". Metrics are recorded per minute by workers configured with the metrics option. start/end are zero-based indices into the data points where 0 is the newest.

Source

pub async fn get_children_values( &self, job_id: &str, ) -> Result<HashMap<String, Value>, Error>

Get return values of all completed children of a parent job.

Source

pub async fn get_failed_children_values( &self, job_id: &str, ) -> Result<HashMap<String, String>, Error>

Get failure values of children that failed with ignoreDependencyOnFailure.

Source

pub async fn get_dependencies_count( &self, job_id: &str, ) -> Result<DependenciesCount, Error>

Get counts of dependencies for a parent job.

Source

pub async fn get_unprocessed_dependencies( &self, job_id: &str, ) -> Result<Vec<String>, Error>

Get unprocessed dependencies (children still pending).

Source

pub async fn remove_child_dependency( &self, job_id: &str, parent_key: &str, ) -> Result<bool, Error>

Remove a child’s dependency from its parent.

job_id - the child job ID parent_key - the fully qualified parent key (prefix:queue:parentId)

Returns true if the dependency was broken, false otherwise.

Source

pub async fn get_job_state(&self, job_id: &str) -> Result<JobState, Error>

Get the state of a specific job.

Source

pub async fn remove(&self, job_id: &str) -> Result<bool, Error>

Remove a job by its ID.

Source

pub async fn remove_without_children(&self, job_id: &str) -> Result<bool, Error>

Remove a job without removing its children.

Children remain in their queues and lose their parent reference.

Source

pub async fn remove_unprocessed_children( &self, job_id: &str, ) -> Result<(), Error>

Remove all unprocessed children of a job.

This removes children that are still in the dependencies set (not yet completed/failed). Active children are skipped.

Source

pub async fn clean( &self, grace: u64, limit: u32, state: &str, ) -> Result<Vec<String>, Error>

Clean jobs from a specific set (completed, failed, etc.).

grace - Only remove jobs older than this many milliseconds. limit - Maximum number of jobs to remove (0 = unlimited). state - Which state set to clean (“completed”, “failed”, “wait”, “active”, “delayed”, “prioritized”, “paused”).

Returns the IDs of removed jobs.

Source

pub async fn drain(&self, delayed: bool) -> Result<(), Error>

Drain the queue (remove all waiting and delayed jobs).

Source

pub async fn retry_jobs( &self, state: &str, count: u32, timestamp: Option<u64>, ) -> Result<(), Error>

Retry all failed (or completed) jobs, moving them back to wait.

  • state: “failed” or “completed” (default: “failed”)
  • count: max jobs to move per batch (default: 1000)
  • timestamp: only retry jobs finished before this timestamp in ms (default: now)
Source

pub async fn promote_jobs(&self, count: u32) -> Result<(), Error>

Promote all delayed jobs to waiting.

  • count: max jobs to promote per batch (default: 1000)
Source

pub async fn rate_limit(&self, expire_time_ms: u64) -> Result<(), Error>

Override the rate limit to be active for the next jobs.

Sets the rate limiter key to MAX value with the given TTL, preventing any new jobs from being processed until it expires.

Source

pub async fn remove_rate_limit_key(&self) -> Result<bool, Error>

Remove the rate limit key, allowing processing to resume immediately.

Source

pub async fn set_global_concurrency( &self, concurrency: u64, ) -> Result<(), Error>

Set global concurrency limit (stored in queue meta hash). Limits the total number of active jobs across all workers for this queue.

Source

pub async fn remove_global_concurrency(&self) -> Result<(), Error>

Remove global concurrency limit from queue meta.

Source

pub async fn set_global_rate_limit( &self, max: u64, duration: u64, ) -> Result<(), Error>

Set global rate limit (stored in queue meta hash).

Source

pub async fn remove_global_rate_limit(&self) -> Result<(), Error>

Remove global rate limit values from queue meta.

Source

pub async fn get_rate_limit_ttl( &self, max_jobs: Option<u64>, ) -> Result<i64, Error>

Return the time-to-live (in ms) for the rate-limited key.

max_jobs is the maximum number of jobs considered in the rate-limit state. When None, the remaining TTL is returned without checking whether the max is exceeded. Returns 0 when not rate limited and -2/-1 mirror Redis PTTL semantics (no key / no expiry).

Source

pub async fn get_global_concurrency(&self) -> Result<Option<u64>, Error>

Return the global concurrency value, or None when not set.

Source

pub async fn get_global_rate_limit(&self) -> Result<Option<(u64, u64)>, Error>

Return the global rate limit as (max, duration), or None when not set.

Source

pub async fn remove_deduplication_key( &self, deduplication_id: &str, job_id: &str, ) -> Result<bool, Error>

Remove a deduplication key if the stored job ID matches the given one.

Uses the removeDeduplicationKey Lua script for atomic check-and-delete.

Source

pub async fn get_deduplication_job_id( &self, deduplication_id: &str, ) -> Result<Option<String>, Error>

Get the job ID stored for a given deduplication ID.

Returns None if no deduplication key exists.

Source

pub async fn get_debounce_job_id( &self, id: &str, ) -> Result<Option<String>, Error>

Get the job ID that started a debounced state.

Deprecated: use Queue::get_deduplication_job_id instead. Provided for parity with the legacy Node.js Queue.getDebounceJobId.

Source

pub async fn remove_debounce_key(&self, id: &str) -> Result<u64, Error>

Remove a debounce key unconditionally, returning the number of keys deleted (0 or 1).

Deprecated: use Queue::remove_deduplication_key instead. Provided for parity with the legacy Node.js Queue.removeDebounceKey. Unlike the deduplication variant, this performs a plain DEL without checking the stored job ID.

Source

pub async fn get_job_logs( &self, job_id: &str, start: isize, end: isize, asc: bool, ) -> Result<(Vec<String>, usize), Error>

Get logs for a specific job.

Returns the log entries and total count.

Source

pub async fn trim_events(&self, max_length: usize) -> Result<usize, Error>

Trim the event stream to approximately max_length entries.

Source

pub async fn update_job_progress( &self, job_id: &str, progress: JobProgress, ) -> Result<(), Error>

Update a job’s progress by id, without loading the job first.

Mirrors Node.js Queue.updateJobProgress: runs the updateProgress script which sets the job’s progress field and emits a progress event on the queue’s event stream.

Source

pub async fn obliterate(&self, force: bool, count: usize) -> Result<(), Error>

Obliterate the queue (remove all keys).

When force is true, automatically pauses the queue first.

Source

pub async fn upsert_job_scheduler( &self, job_scheduler_id: &str, repeat_opts: RepeatOptions, job_name: Option<&str>, job_data: Option<Value>, job_opts: Option<JobOptions>, ) -> Result<Option<Job>, Error>

Create or update a job scheduler.

Creates a scheduled repeating job that will run on a cron pattern or at fixed intervals. The scheduler is persisted in Redis and will create the next delayed job automatically after each execution.

§Arguments
  • job_scheduler_id — Unique ID for this scheduler.
  • repeat_opts — Schedule configuration (cron pattern or every-ms).
  • job_name — Name for the created jobs (defaults to scheduler ID).
  • job_data — JSON data for the created jobs.
  • job_opts — Options for the created jobs (attempts, backoff, etc.).
Source

pub async fn get_job_scheduler( &self, job_scheduler_id: &str, ) -> Result<Option<JobSchedulerJson>, Error>

Get a job scheduler by its ID.

Source

pub async fn get_job_schedulers( &self, start: isize, end: isize, asc: bool, ) -> Result<Vec<JobSchedulerJson>, Error>

Get a paginated list of job schedulers.

Returns schedulers ordered by next execution time.

Source

pub async fn get_job_schedulers_count(&self) -> Result<u64, Error>

Get the total number of job schedulers.

Source

pub async fn remove_job_scheduler( &self, job_scheduler_id: &str, ) -> Result<bool, Error>

Remove a job scheduler by its ID.

Also removes the next scheduled delayed job if one exists. Returns true if the scheduler was found and removed.

Source

pub async fn close(&self)

Close the queue connection.

Trait Implementations§

Source§

impl Clone for Queue

Source§

fn clone(&self) -> Queue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Queue

§

impl RefUnwindSafe for Queue

§

impl Send for Queue

§

impl Sync for Queue

§

impl Unpin for Queue

§

impl UnsafeUnpin for Queue

§

impl UnwindSafe for Queue

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more