Skip to main content

QueueExecutor

Struct QueueExecutor 

Source
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

Source

pub fn new(config: QueueConfig, db: Arc<Mutex<Connection>>) -> Self

Source

pub fn spawn<H>(self: Arc<Self>, 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.

Source

pub fn spawn_on<H>( self: Arc<Self>, 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()).

Source

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.

Source

pub fn resume(&self)

Resume the executor after a pause.

Source

pub fn is_paused(&self) -> bool

Check if the executor is currently paused.

Source

pub fn shutdown(&self)

Signal the executor to shut down gracefully.

The currently running job (if any) will finish, then the loop exits.

Source

pub fn is_shutdown(&self) -> bool

Check if a shutdown has been requested.

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 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).

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