openzeppelin_relayer/bootstrap/initialize_workers.rs
1//! Worker initialization
2//!
3//! Re-exports from the queue backend module where the Apalis-specific worker
4//! logic now lives alongside the Redis backend implementation.
5//!
6//! Also provides `initialize_queue_workers` which consolidates the entire
7//! queue backend lifecycle (creation, worker init) into a single call.
8
9use std::sync::Arc;
10
11use actix_web::web::ThinData;
12use tracing::info;
13
14use crate::{
15 models::DefaultAppState,
16 queues::{QueueBackend, WorkerHandle},
17};
18
19/// Creates the queue backend and initializes all workers in a single step.
20///
21/// This consolidates queue backend creation (from `QUEUE_BACKEND` env var),
22/// worker initialization, and logging into a single bootstrap function,
23/// keeping `main.rs` free of queue implementation details.
24///
25/// # Arguments
26/// * `app_state` - Application state containing the job producer and configuration
27///
28/// # Returns
29/// Vector of worker handles for all spawned workers
30pub async fn initialize_queue_workers(
31 app_state: ThinData<DefaultAppState>,
32) -> color_eyre::Result<Vec<WorkerHandle>> {
33 let backend = app_state.job_producer.queue_backend();
34
35 let handles = backend.initialize_workers(Arc::new(app_state)).await?;
36
37 info!(
38 backend = %backend.backend_type(),
39 worker_count = handles.len(),
40 "Initialized queue backend workers"
41 );
42
43 Ok(handles)
44}