pub struct WorkerService<Q, S, E, F>{ /* private fields */ }Expand description
Worker service that processes jobs from the queue.
This service polls for pending jobs and processes them using the
HarvestService. It supports graceful shutdown via cancellation tokens.
Implementations§
Source§impl<Q, S, E, F> WorkerService<Q, S, E, F>
impl<Q, S, E, F> WorkerService<Q, S, E, F>
Sourcepub fn new(
queue: Q,
harvest_service: HarvestService<S, E, F>,
config: WorkerConfig,
) -> Self
pub fn new( queue: Q, harvest_service: HarvestService<S, E, F>, config: WorkerConfig, ) -> Self
Create a new worker service.
Sourcepub async fn run<WR, HR>(
&self,
cancel_token: CancellationToken,
worker_reporter: &WR,
harvest_reporter: &HR,
) -> Result<(), AppError>where
WR: WorkerReporter,
HR: ProgressReporter,
pub async fn run<WR, HR>(
&self,
cancel_token: CancellationToken,
worker_reporter: &WR,
harvest_reporter: &HR,
) -> Result<(), AppError>where
WR: WorkerReporter,
HR: ProgressReporter,
Run the worker until cancelled.
The worker will:
- Poll for available jobs
- Claim and process jobs
- Handle retries on failure
- Release jobs on graceful shutdown
Sourcepub async fn process_single_job<WR, HR>(
&self,
job_id: Uuid,
cancel_token: CancellationToken,
worker_reporter: &WR,
harvest_reporter: &HR,
) -> Result<(), AppError>where
WR: WorkerReporter,
HR: ProgressReporter,
pub async fn process_single_job<WR, HR>(
&self,
job_id: Uuid,
cancel_token: CancellationToken,
worker_reporter: &WR,
harvest_reporter: &HR,
) -> Result<(), AppError>where
WR: WorkerReporter,
HR: ProgressReporter,
Process a single job by ID (for one-off execution, e.g., CLI).
This method is useful for processing a specific job without running the full polling loop.
Auto Trait Implementations§
impl<Q, S, E, F> Freeze for WorkerService<Q, S, E, F>
impl<Q, S, E, F> RefUnwindSafe for WorkerService<Q, S, E, F>
impl<Q, S, E, F> Send for WorkerService<Q, S, E, F>
impl<Q, S, E, F> Sync for WorkerService<Q, S, E, F>
impl<Q, S, E, F> Unpin for WorkerService<Q, S, E, F>
impl<Q, S, E, F> UnwindSafe for WorkerService<Q, S, E, F>
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more