Skip to main content

sockudo_core/
queue.rs

1use crate::error::Result;
2use crate::webhook_types::{JobData, JobProcessorFnAsync};
3use async_trait::async_trait;
4use serde::Serialize;
5use serde::de::DeserializeOwned;
6use std::future::Future;
7use std::pin::Pin;
8use std::sync::Arc;
9
10impl JobData where JobData: Serialize + DeserializeOwned {}
11
12// Define a type alias for the callback for clarity and easier management
13#[allow(dead_code)]
14type JobProcessorFn = Box<dyn Fn(JobData) -> Result<()> + Send + Sync + 'static>;
15// Define a type alias for the Arc'd callback used in Redis manager
16#[allow(dead_code)]
17type ArcJobProcessorFn = Arc<
18    Box<
19        dyn Fn(JobData) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> + Send + Sync + 'static,
20    >,
21>;
22
23#[async_trait]
24pub trait QueueInterface: Send + Sync {
25    async fn add_to_queue(&self, queue_name: &str, data: JobData) -> crate::error::Result<()>;
26    // Changed callback type to accept 'static lifetime needed by Redis workers
27    async fn process_queue(
28        &self,
29        queue_name: &str,
30        callback: JobProcessorFnAsync,
31    ) -> crate::error::Result<()>;
32    async fn disconnect(&self) -> crate::error::Result<()>;
33    async fn check_health(&self) -> crate::error::Result<()>;
34}