Skip to main content

QueueManager

Struct QueueManager 

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

High-level queue manager providing the public API.

Create a QueueManager, add jobs to it, then call spawn() to start the background executor that processes them.

§Example

let config = QueueConfig::builder()
    .with_db_path(PathBuf::from("queue.db"))
    .build();

let manager = QueueManager::new(config).unwrap();
let job = QueueJob::new(MyJob { ... });
manager.add(job).unwrap();

manager.spawn::<MyJob>(Arc::new(LoggingEventEmitter));

Implementations§

Source§

impl QueueManager

Source

pub fn new(config: QueueConfig) -> Result<QueueManager, QueueError>

Create a new queue manager with the given configuration.

Opens (or creates) the SQLite database and requeues any jobs that were interrupted by a previous crash.

Source

pub fn add<H>(&self, job: QueueJob<H>) -> Result<String, QueueError>
where H: JobHandler,

Add a job to the queue. Returns the job ID.

Source

pub fn cancel(&self, job_id: &str) -> Result<(), QueueError>

Cancel a pending or processing job by ID.

Source

pub fn reorder( &self, job_id: &str, new_priority: QueuePriority, ) -> Result<(), QueueError>

Reorder a pending job to a new priority.

Source

pub fn pause(&self)

Pause the queue. The current job will finish, but no new jobs start.

Source

pub fn resume(&self)

Resume the queue after a pause.

Source

pub fn is_paused(&self) -> bool

Check if the queue is currently paused.

Source

pub fn list_jobs(&self) -> Result<Vec<(String, String)>, QueueError>

Get all jobs as (id, status) pairs, ordered by status then priority.

Source

pub fn list_jobs_with_data( &self, ) -> Result<Vec<(String, String, String)>, QueueError>

Get all jobs as (id, status, data_json) tuples.

Source

pub fn get_job_details( &self, job_id: &str, ) -> Result<Option<QueueJobDetails>, QueueError>

Fetch a structured view of a single job for debugging or UI inspection.

Source

pub fn prune(&self, days: u32) -> Result<u32, QueueError>

Prune completed/failed/cancelled jobs older than days. Returns the number of jobs deleted.

Source

pub async fn process_one<H>( &self, event_emitter: &Arc<dyn QueueEventEmitter>, ) -> Result<Option<ProcessedJob>, QueueError>
where H: JobHandler,

Process the next pending job in the foreground and return the result.

Returns Ok(None) if no pending jobs are available. Unlike spawn(), this does not start a background loop — it processes exactly one job and returns. Useful for CLI-driven loops where cascade logic runs between jobs.

Source

pub fn count_by_status(&self) -> Result<QueueStats, QueueError>

Count jobs by status.

Source

pub fn shutdown(&self)

Signal the executor to shut down gracefully.

The currently running job (if any) will finish, then the background loop exits. This is safe to call multiple times.

Source

pub fn is_shutdown(&self) -> bool

Check if a shutdown has been requested.

Source

pub fn worker_id(&self) -> &str

Returns the configured worker identifier.

Source

pub fn spawn<H>( self, event_emitter: Arc<dyn QueueEventEmitter>, ) -> Arc<QueueManager>
where H: JobHandler + 'static,

Spawn the background executor and return the manager wrapped in an Arc.

The event emitter receives notifications about job lifecycle events.

If the current thread is inside a tokio runtime, the executor loop is spawned directly. Otherwise (e.g., during Tauri’s synchronous setup() phase), a dedicated background thread is created automatically.

Source

pub fn spawn_on<H>( self, event_emitter: Arc<dyn QueueEventEmitter>, handle: &Handle, ) -> Arc<QueueManager>
where H: JobHandler + 'static,

Spawn the background executor on a specific tokio runtime handle.

Use this instead of spawn() when you have an explicit runtime handle (e.g., from tauri::async_runtime::handle()).

Auto Trait Implementations§

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> 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, 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