pub struct QueueExecutor { /* private fields */ }Expand description
The background job executor.
Polls the database for pending jobs and processes them using the
registered JobHandler implementation. Supports pause/resume,
consecutive job limits with cooldown, graceful shutdown, and cancellation.
Implementations§
Source§impl QueueExecutor
impl QueueExecutor
pub fn new(config: QueueConfig, db: Arc<Mutex<Connection>>) -> QueueExecutor
Sourcepub fn spawn<H>(
self: Arc<QueueExecutor>,
event_emitter: Arc<dyn QueueEventEmitter>,
)where
H: JobHandler + 'static,
pub fn spawn<H>(
self: Arc<QueueExecutor>,
event_emitter: Arc<dyn QueueEventEmitter>,
)where
H: JobHandler + 'static,
Spawn the executor loop as a background tokio task.
The executor will poll for pending jobs at the configured interval
and process them using the provided JobHandler implementation.
If the current thread is inside a tokio runtime, the loop is spawned
directly via tokio::spawn. Otherwise (e.g., during Tauri’s synchronous
setup() phase), a dedicated background thread with its own single-threaded
tokio runtime is created automatically.
Sourcepub fn spawn_on<H>(
self: Arc<QueueExecutor>,
event_emitter: Arc<dyn QueueEventEmitter>,
handle: &Handle,
)where
H: JobHandler + 'static,
pub fn spawn_on<H>(
self: Arc<QueueExecutor>,
event_emitter: Arc<dyn QueueEventEmitter>,
handle: &Handle,
)where
H: JobHandler + 'static,
Spawn the executor loop 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()).
Sourcepub fn pause(&self)
pub fn pause(&self)
Pause the executor. The current job (if any) will finish,
but no new jobs will be started until resume() is called.
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 loop exits.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Check if a shutdown has been requested.
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 and return the result.
Unlike spawn(), this method processes exactly one job
in the foreground and returns. Returns Ok(None) if no pending jobs
are available.
This is useful for CLI tools that want to drive the execution loop manually (e.g., to run cascade logic between jobs).