pub struct JobQueue { /* private fields */ }Expand description
The job queue engine.
Thread-safe: all internal state is behind mutexes, and a Condvar wakes
blocked workers when new jobs arrive.
Implementations§
Source§impl JobQueue
impl JobQueue
pub fn new(max_history: usize) -> Self
Sourcepub fn attach_store(&self, store: Arc<JobStore>)
pub fn attach_store(&self, store: Arc<JobStore>)
Attach a persistent store. After this, every enqueue, state change, and terminal event is mirrored to the store. Call once at startup.
Sourcepub fn register(&self, job_name: &str, handler: JobHandler)
pub fn register(&self, job_name: &str, handler: JobHandler)
Register a handler for a job type.
Sourcepub fn enqueue(&self, name: &str, payload: Value) -> String
pub fn enqueue(&self, name: &str, payload: Value) -> String
Enqueue a new job with default options. Returns the job ID.
Sourcepub fn enqueue_with_options(
&self,
name: &str,
payload: Value,
priority: Priority,
delay_secs: u64,
max_retries: u32,
queue: &str,
) -> String
pub fn enqueue_with_options( &self, name: &str, payload: Value, priority: Priority, delay_secs: u64, max_retries: u32, queue: &str, ) -> String
Enqueue with full options. Returns the job id, or an empty string if
the persistent store rejected the write. Prefer
[try_enqueue_with_options] in new code so persist failures don’t
look like success to the caller.
Sourcepub fn try_enqueue_with_options(
&self,
name: &str,
payload: Value,
priority: Priority,
delay_secs: u64,
max_retries: u32,
queue: &str,
) -> Result<String, String>
pub fn try_enqueue_with_options( &self, name: &str, payload: Value, priority: Priority, delay_secs: u64, max_retries: u32, queue: &str, ) -> Result<String, String>
Result-returning variant of [enqueue_with_options]. Use this from
any path where a silent failure would propagate as an apparent
success (e.g. the TS scheduler hook returning id: "" to the user).
Sourcepub fn dequeue(&self, timeout: Duration) -> Option<Job>
pub fn dequeue(&self, timeout: Duration) -> Option<Job>
Dequeue the highest-priority pending job whose delay_secs has
elapsed. Blocks up to timeout if nothing is ready.
Sourcepub fn dequeue_from(&self, queue: &str, timeout: Duration) -> Option<Job>
pub fn dequeue_from(&self, queue: &str, timeout: Duration) -> Option<Job>
Dequeue from a specific queue. Blocks up to timeout if nothing
in the queue is ready (delay-respecting).
Sourcepub fn fail(&self, job_id: &str, error: &str)
pub fn fail(&self, job_id: &str, error: &str)
Mark a job as failed. Retries if under max_retries.
Sourcepub fn process_one(&self) -> bool
pub fn process_one(&self) -> bool
Process the next available job using registered handlers. Returns true if a job was processed.
Sourcepub fn get_job(&self, id: &str) -> Option<Job>
pub fn get_job(&self, id: &str) -> Option<Job>
Get job by ID (searches pending, running, history, dead letters).
Sourcepub fn stats(&self) -> QueueStats
pub fn stats(&self) -> QueueStats
Get queue statistics.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Get pending job count.
Sourcepub fn running_count(&self) -> usize
pub fn running_count(&self) -> usize
Get running job count.
Sourcepub fn dead_letters(&self) -> Vec<Job>
pub fn dead_letters(&self) -> Vec<Job>
Get dead letter queue contents.
Sourcepub fn retry_dead(&self, job_id: &str) -> bool
pub fn retry_dead(&self, job_id: &str) -> bool
Retry a dead letter by moving it back to pending.
Sourcepub fn recent_history(&self, limit: usize) -> Vec<Job>
pub fn recent_history(&self, limit: usize) -> Vec<Job>
Get recent job history.
Sourcepub fn list_jobs(
&self,
status: Option<&str>,
queue: Option<&str>,
limit: usize,
) -> Vec<Job>
pub fn list_jobs( &self, status: Option<&str>, queue: Option<&str>, limit: usize, ) -> Vec<Job>
List pending jobs with optional status/queue filters.
Sourcepub fn restore_from(&self, store: &JobStore) -> usize
pub fn restore_from(&self, store: &JobStore) -> usize
Restore pending/running/retrying jobs from a persistent store.
Jobs that were Running at the time of the crash are reset to
Pending so they will be re-processed. Returns the number of jobs
restored.
Call this once at startup, before workers begin processing.
Trait Implementations§
Source§impl JobOps for JobQueue
impl JobOps for JobQueue
fn enqueue( &self, name: &str, payload: Value, priority: &str, delay_secs: u64, max_retries: u32, queue: &str, ) -> String
fn stats(&self) -> Value
fn dead_letters(&self) -> Value
fn retry_dead(&self, id: &str) -> bool
fn list_jobs( &self, status: Option<&str>, queue: Option<&str>, limit: usize, ) -> Value
fn get_job(&self, id: &str) -> Option<Value>
Auto Trait Implementations§
impl !Freeze for JobQueue
impl RefUnwindSafe for JobQueue
impl Send for JobQueue
impl Sync for JobQueue
impl Unpin for JobQueue
impl UnsafeUnpin for JobQueue
impl UnwindSafe for JobQueue
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> 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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);