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
impl QueueManager
Sourcepub fn new(config: QueueConfig) -> Result<QueueManager, QueueError>
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.
Sourcepub fn add<H>(&self, job: QueueJob<H>) -> Result<String, QueueError>where
H: JobHandler,
pub fn add<H>(&self, job: QueueJob<H>) -> Result<String, QueueError>where
H: JobHandler,
Add a job to the queue. Returns the job ID.
Sourcepub fn cancel(&self, job_id: &str) -> Result<(), QueueError>
pub fn cancel(&self, job_id: &str) -> Result<(), QueueError>
Cancel a pending or processing job by ID.
Sourcepub fn reorder(
&self,
job_id: &str,
new_priority: QueuePriority,
) -> Result<(), QueueError>
pub fn reorder( &self, job_id: &str, new_priority: QueuePriority, ) -> Result<(), QueueError>
Reorder a pending job to a new priority.
Sourcepub fn list_jobs(&self) -> Result<Vec<(String, String)>, QueueError>
pub fn list_jobs(&self) -> Result<Vec<(String, String)>, QueueError>
Get all jobs as (id, status) pairs, ordered by status then priority.
Sourcepub fn list_jobs_with_data(
&self,
) -> Result<Vec<(String, String, String)>, QueueError>
pub fn list_jobs_with_data( &self, ) -> Result<Vec<(String, String, String)>, QueueError>
Get all jobs as (id, status, data_json) tuples.
Sourcepub fn get_job_details(
&self,
job_id: &str,
) -> Result<Option<QueueJobDetails>, QueueError>
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.
Sourcepub fn prune(&self, days: u32) -> Result<u32, QueueError>
pub fn prune(&self, days: u32) -> Result<u32, QueueError>
Prune completed/failed/cancelled jobs older than days.
Returns the number of jobs deleted.
Sourcepub async fn process_one<H>(
&self,
event_emitter: &Arc<dyn QueueEventEmitter>,
) -> Result<Option<ProcessedJob>, QueueError>where
H: JobHandler,
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.
Sourcepub fn count_by_status(&self) -> Result<QueueStats, QueueError>
pub fn count_by_status(&self) -> Result<QueueStats, QueueError>
Count jobs by status.
Sourcepub fn shutdown(&self)
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.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Check if a shutdown has been requested.
Sourcepub fn spawn<H>(
self,
event_emitter: Arc<dyn QueueEventEmitter>,
) -> Arc<QueueManager>where
H: JobHandler + 'static,
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.
Sourcepub fn spawn_on<H>(
self,
event_emitter: Arc<dyn QueueEventEmitter>,
handle: &Handle,
) -> Arc<QueueManager>where
H: JobHandler + 'static,
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()).