1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#![warn(
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
unreachable_pub
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
//! # apalis-sql
//! apalis offers Sqlite, Mysql and Postgres storages for its workers.
//! See relevant modules for examples
use std::time::Duration;
/// The context of the sql job
pub mod context;
/// Util for fetching rows
pub mod from_row;
/// Postgres storage for apalis. Uses `NOTIFY` and `SKIP LOCKED`
#[cfg(feature = "postgres")]
#[cfg_attr(docsrs, doc(cfg(feature = "postgres")))]
pub mod postgres;
/// Sqlite Storage for apalis.
/// Uses a transaction and min(rowid)
#[cfg(feature = "sqlite")]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
pub mod sqlite;
/// MySQL storage for apalis. Uses `SKIP LOCKED`
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
pub mod mysql;
/// Config for sql storages
#[derive(Debug, Clone)]
pub struct Config {
keep_alive: Duration,
buffer_size: usize,
poll_interval: Duration,
namespace: String,
}
impl Default for Config {
fn default() -> Self {
Self {
keep_alive: Duration::from_secs(30),
buffer_size: 10,
poll_interval: Duration::from_millis(50),
namespace: String::from("apalis::sql"),
}
}
}
impl Config {
/// Create a new config with a jobs namespace
pub fn new(namespace: &str) -> Self {
Config::default().namespace(namespace)
}
/// Interval between database poll queries
///
/// Defaults to 30ms
pub fn poll_interval(mut self, interval: Duration) -> Self {
self.poll_interval = interval;
self
}
/// Interval between worker keep-alive database updates
///
/// Defaults to 30s
pub fn keep_alive(mut self, keep_alive: Duration) -> Self {
self.keep_alive = keep_alive;
self
}
/// Buffer size to use when querying for jobs
///
/// Defaults to 10
pub fn buffer_size(mut self, buffer_size: usize) -> Self {
self.buffer_size = buffer_size;
self
}
/// Set the namespace to consume and push jobs to
///
/// Defaults to "apalis::sql"
pub fn namespace(mut self, namespace: &str) -> Self {
self.namespace = namespace.to_owned();
self
}
}