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
impl Queue
Sourcepub async fn new(name: &str, opts: QueueOptions) -> Result<Self, Error>
pub async fn new(name: &str, opts: QueueOptions) -> Result<Self, Error>
Create a new Queue connected to Redis.
Sourcepub async fn with_connection(
name: &str,
conn: RedisConnection,
opts: QueueOptions,
) -> Result<Self, Error>
pub async fn with_connection( name: &str, conn: RedisConnection, opts: QueueOptions, ) -> Result<Self, Error>
Create a Queue with an existing Redis connection.
Sourcepub fn connection(&self) -> &RedisConnection
pub fn connection(&self) -> &RedisConnection
The underlying Redis connection.
Sourcepub async fn add(
&self,
name: &str,
data: Value,
opts: Option<JobOptions>,
) -> Result<Job, Error>
pub async fn add( &self, name: &str, data: Value, opts: Option<JobOptions>, ) -> Result<Job, Error>
Add a job to the queue.
Sourcepub async fn add_bulk(
&self,
jobs: Vec<(String, Value, Option<JobOptions>)>,
) -> Result<Vec<Job>, Error>
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.
Sourcepub async fn get_job_counts(&self) -> Result<JobCounts, Error>
pub async fn get_job_counts(&self) -> Result<JobCounts, Error>
Get the counts of jobs in each state.
Sourcepub async fn get_ranges(
&self,
types: &[&str],
start: i64,
end: i64,
asc: bool,
) -> Result<Vec<String>, Error>
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.
Sourcepub async fn get_jobs(
&self,
types: &[&str],
start: i64,
end: i64,
asc: bool,
) -> Result<Vec<Job>, Error>
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.
Sourcepub async fn get_waiting(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>
pub async fn get_waiting(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>
Return jobs in the waiting (and paused) state.
Sourcepub async fn get_waiting_children(
&self,
start: i64,
end: i64,
) -> Result<Vec<Job>, Error>
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).
Sourcepub async fn get_active(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>
pub async fn get_active(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>
Return jobs in the active state.
Sourcepub async fn get_delayed(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>
pub async fn get_delayed(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>
Return jobs in the delayed state.
Sourcepub async fn get_prioritized(
&self,
start: i64,
end: i64,
) -> Result<Vec<Job>, Error>
pub async fn get_prioritized( &self, start: i64, end: i64, ) -> Result<Vec<Job>, Error>
Return jobs in the prioritized state.
Sourcepub async fn get_completed(
&self,
start: i64,
end: i64,
) -> Result<Vec<Job>, Error>
pub async fn get_completed( &self, start: i64, end: i64, ) -> Result<Vec<Job>, Error>
Return jobs in the completed state.
Sourcepub async fn get_failed(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>
pub async fn get_failed(&self, start: i64, end: i64) -> Result<Vec<Job>, Error>
Return jobs in the failed state.
Sourcepub async fn get_job_counts_by_types(
&self,
types: &[&str],
) -> Result<HashMap<String, u64>, Error>
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.
Sourcepub async fn get_job_count_by_types(&self, types: &[&str]) -> Result<u64, Error>
pub async fn get_job_count_by_types(&self, types: &[&str]) -> Result<u64, Error>
Return the total number of jobs across the provided types.
Sourcepub async fn record_job_counts_metric(
&self,
types: &[&str],
recorder: Option<JobCountRecorder<'_>>,
) -> Result<HashMap<String, u64>, Error>
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.
Sourcepub async fn count(&self) -> Result<u64, Error>
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.
Sourcepub async fn get_counts_per_priority(
&self,
priorities: &[u64],
) -> Result<HashMap<u64, u64>, Error>
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.
Sourcepub async fn get_completed_count(&self) -> Result<u64, Error>
pub async fn get_completed_count(&self) -> Result<u64, Error>
Return the number of jobs in the completed state.
Sourcepub async fn get_failed_count(&self) -> Result<u64, Error>
pub async fn get_failed_count(&self) -> Result<u64, Error>
Return the number of jobs in the failed state.
Sourcepub async fn get_delayed_count(&self) -> Result<u64, Error>
pub async fn get_delayed_count(&self) -> Result<u64, Error>
Return the number of jobs in the delayed state.
Sourcepub async fn get_active_count(&self) -> Result<u64, Error>
pub async fn get_active_count(&self) -> Result<u64, Error>
Return the number of jobs in the active state.
Sourcepub async fn get_prioritized_count(&self) -> Result<u64, Error>
pub async fn get_prioritized_count(&self) -> Result<u64, Error>
Return the number of jobs in the prioritized state.
Sourcepub async fn get_waiting_count(&self) -> Result<u64, Error>
pub async fn get_waiting_count(&self) -> Result<u64, Error>
Return the number of jobs in the waiting (and paused) state.
Sourcepub async fn get_waiting_children_count(&self) -> Result<u64, Error>
pub async fn get_waiting_children_count(&self) -> Result<u64, Error>
Return the number of jobs in the waiting-children state.
Sourcepub async fn get_workers(&self) -> Result<Vec<HashMap<String, String>>, Error>
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.
Sourcepub async fn get_workers_count(&self) -> Result<usize, Error>
pub async fn get_workers_count(&self) -> Result<usize, Error>
Return the number of workers currently connected to this queue.
Sourcepub async fn get_meta(&self) -> Result<QueueMeta, Error>
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.
Sourcepub async fn get_version(&self) -> Result<Option<String>, Error>
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.
Sourcepub async fn is_maxed(&self) -> Result<bool, Error>
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.
Sourcepub async fn export_prometheus_metrics(
&self,
global_labels: &[(&str, &str)],
) -> Result<String, Error>
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.
Sourcepub async fn get_metrics(
&self,
metric_type: &str,
start: i64,
end: i64,
) -> Result<Metrics, Error>
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.
Sourcepub async fn get_children_values(
&self,
job_id: &str,
) -> Result<HashMap<String, Value>, Error>
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.
Sourcepub async fn get_failed_children_values(
&self,
job_id: &str,
) -> Result<HashMap<String, String>, Error>
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.
Sourcepub async fn get_dependencies_count(
&self,
job_id: &str,
) -> Result<DependenciesCount, Error>
pub async fn get_dependencies_count( &self, job_id: &str, ) -> Result<DependenciesCount, Error>
Get counts of dependencies for a parent job.
Sourcepub async fn get_unprocessed_dependencies(
&self,
job_id: &str,
) -> Result<Vec<String>, Error>
pub async fn get_unprocessed_dependencies( &self, job_id: &str, ) -> Result<Vec<String>, Error>
Get unprocessed dependencies (children still pending).
Sourcepub async fn remove_child_dependency(
&self,
job_id: &str,
parent_key: &str,
) -> Result<bool, Error>
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.
Sourcepub async fn get_job_state(&self, job_id: &str) -> Result<JobState, Error>
pub async fn get_job_state(&self, job_id: &str) -> Result<JobState, Error>
Get the state of a specific job.
Sourcepub async fn remove_without_children(&self, job_id: &str) -> Result<bool, Error>
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.
Sourcepub async fn remove_unprocessed_children(
&self,
job_id: &str,
) -> Result<(), Error>
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.
Sourcepub async fn clean(
&self,
grace: u64,
limit: u32,
state: &str,
) -> Result<Vec<String>, Error>
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.
Sourcepub async fn drain(&self, delayed: bool) -> Result<(), Error>
pub async fn drain(&self, delayed: bool) -> Result<(), Error>
Drain the queue (remove all waiting and delayed jobs).
Sourcepub async fn retry_jobs(
&self,
state: &str,
count: u32,
timestamp: Option<u64>,
) -> Result<(), Error>
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)
Sourcepub async fn promote_jobs(&self, count: u32) -> Result<(), Error>
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)
Sourcepub async fn rate_limit(&self, expire_time_ms: u64) -> Result<(), Error>
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.
Sourcepub async fn remove_rate_limit_key(&self) -> Result<bool, Error>
pub async fn remove_rate_limit_key(&self) -> Result<bool, Error>
Remove the rate limit key, allowing processing to resume immediately.
Sourcepub async fn set_global_concurrency(
&self,
concurrency: u64,
) -> Result<(), Error>
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.
Sourcepub async fn remove_global_concurrency(&self) -> Result<(), Error>
pub async fn remove_global_concurrency(&self) -> Result<(), Error>
Remove global concurrency limit from queue meta.
Sourcepub async fn set_global_rate_limit(
&self,
max: u64,
duration: u64,
) -> Result<(), Error>
pub async fn set_global_rate_limit( &self, max: u64, duration: u64, ) -> Result<(), Error>
Set global rate limit (stored in queue meta hash).
Sourcepub async fn remove_global_rate_limit(&self) -> Result<(), Error>
pub async fn remove_global_rate_limit(&self) -> Result<(), Error>
Remove global rate limit values from queue meta.
Sourcepub async fn get_rate_limit_ttl(
&self,
max_jobs: Option<u64>,
) -> Result<i64, Error>
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).
Sourcepub async fn get_global_concurrency(&self) -> Result<Option<u64>, Error>
pub async fn get_global_concurrency(&self) -> Result<Option<u64>, Error>
Return the global concurrency value, or None when not set.
Sourcepub async fn get_global_rate_limit(&self) -> Result<Option<(u64, u64)>, Error>
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.
Sourcepub async fn remove_deduplication_key(
&self,
deduplication_id: &str,
job_id: &str,
) -> Result<bool, Error>
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.
Sourcepub async fn get_deduplication_job_id(
&self,
deduplication_id: &str,
) -> Result<Option<String>, Error>
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.
Sourcepub async fn get_debounce_job_id(
&self,
id: &str,
) -> Result<Option<String>, Error>
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.
Sourcepub async fn remove_debounce_key(&self, id: &str) -> Result<u64, Error>
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.
Sourcepub async fn get_job_logs(
&self,
job_id: &str,
start: isize,
end: isize,
asc: bool,
) -> Result<(Vec<String>, usize), Error>
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.
Sourcepub async fn trim_events(&self, max_length: usize) -> Result<usize, Error>
pub async fn trim_events(&self, max_length: usize) -> Result<usize, Error>
Trim the event stream to approximately max_length entries.
Sourcepub async fn update_job_progress(
&self,
job_id: &str,
progress: JobProgress,
) -> Result<(), Error>
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.
Sourcepub async fn obliterate(&self, force: bool, count: usize) -> Result<(), Error>
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.
Sourcepub 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>
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.).
Sourcepub async fn get_job_scheduler(
&self,
job_scheduler_id: &str,
) -> Result<Option<JobSchedulerJson>, Error>
pub async fn get_job_scheduler( &self, job_scheduler_id: &str, ) -> Result<Option<JobSchedulerJson>, Error>
Get a job scheduler by its ID.
Sourcepub async fn get_job_schedulers(
&self,
start: isize,
end: isize,
asc: bool,
) -> Result<Vec<JobSchedulerJson>, Error>
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.
Sourcepub async fn get_job_schedulers_count(&self) -> Result<u64, Error>
pub async fn get_job_schedulers_count(&self) -> Result<u64, Error>
Get the total number of job schedulers.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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