pub trait ShouldQueue {
// Provided methods
fn queue(&self) -> &'static str { ... }
fn delay(&self) -> Option<u64> { ... }
fn max_retries(&self) -> u32 { ... }
}Expand description
Marker trait for listeners that should be queued for background processing.
Listeners implementing this trait will not be executed immediately. Instead, they will be pushed to a job queue and processed asynchronously by a worker.
§Example
use ferro_events::{Event, Listener, ShouldQueue, Error, async_trait};
#[derive(Clone)]
struct LargeFileUploaded { path: String }
impl Event for LargeFileUploaded {
fn name(&self) -> &'static str { "LargeFileUploaded" }
}
struct ProcessUploadedFile;
impl ShouldQueue for ProcessUploadedFile {
fn queue(&self) -> &'static str {
"file-processing"
}
}
#[async_trait]
impl Listener<LargeFileUploaded> for ProcessUploadedFile {
async fn handle(&self, event: &LargeFileUploaded) -> Result<(), Error> {
// This will run in a background worker
println!("Processing file: {}", event.path);
Ok(())
}
}Provided Methods§
Sourcefn max_retries(&self) -> u32
fn max_retries(&self) -> u32
The number of times to retry on failure.