#[cfg(feature = "redis")]
pub fn redis_broker(
url: &str,
queue: &str,
) -> std::result::Result<crate::RedisBroker, celers_core::error::CelersError> {
let full_url = if url.starts_with("redis://") {
url.to_string()
} else {
format!("redis://{}", url)
};
crate::RedisBroker::new(&full_url, queue)
}
#[cfg(feature = "postgres")]
pub async fn postgres_broker(
url: &str,
queue: &str,
) -> std::result::Result<crate::PostgresBroker, celers_core::error::CelersError> {
crate::PostgresBroker::with_queue(url, queue).await
}
#[cfg(feature = "mysql")]
pub async fn mysql_broker(
url: &str,
queue: &str,
) -> std::result::Result<crate::MysqlBroker, celers_core::error::CelersError> {
crate::MysqlBroker::with_queue(url, queue).await
}
#[cfg(feature = "amqp")]
pub async fn amqp_broker(
url: &str,
queue: &str,
) -> std::result::Result<crate::AmqpBroker, celers_core::error::CelersError> {
crate::AmqpBroker::new(url, queue)
.await
.map_err(|e| celers_core::error::CelersError::Broker(e.to_string()))
}
#[cfg(feature = "sqs")]
pub async fn sqs_broker(
queue: &str,
) -> std::result::Result<crate::SqsBroker, celers_core::error::CelersError> {
crate::SqsBroker::new(queue)
.await
.map_err(|e| celers_core::error::CelersError::Broker(e.to_string()))
}
pub fn default_worker_config() -> std::result::Result<crate::WorkerConfig, String> {
use celers_worker::WorkerConfigBuilder;
WorkerConfigBuilder::new()
.concurrency(num_cpus::get())
.build()
}
pub fn worker_config_with_concurrency(
concurrency: usize,
) -> std::result::Result<crate::WorkerConfig, String> {
use celers_worker::WorkerConfigBuilder;
WorkerConfigBuilder::new().concurrency(concurrency).build()
}