Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Config accessible publicly #364

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions packages/apalis-sql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,73 @@ impl Default for Config {
impl Config {
/// Create a new config with a jobs namespace
pub fn new(namespace: &str) -> Self {
Config::default().namespace(namespace)
Config::default().set_namespace(namespace)
}

/// Interval between database poll queries
///
/// Defaults to 30ms
pub fn poll_interval(mut self, interval: Duration) -> Self {
pub fn set_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 {
pub fn set_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 {
pub fn set_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 {
pub fn set_namespace(mut self, namespace: &str) -> Self {
self.namespace = namespace.to_owned();
self
}

/// Gets a reference to the keep_alive duration.
pub fn keep_alive(&self) -> &Duration {
&self.keep_alive
}

/// Gets a mutable reference to the keep_alive duration.
pub fn keep_alive_mut(&mut self) -> &mut Duration {
&mut self.keep_alive
}

/// Gets the buffer size.
pub fn buffer_size(&self) -> usize {
self.buffer_size
}

/// Gets a reference to the poll_interval duration.
pub fn poll_interval(&self) -> &Duration {
&self.poll_interval
}

/// Gets a mutable reference to the poll_interval duration.
pub fn poll_interval_mut(&mut self) -> &mut Duration {
&mut self.poll_interval
}

/// Gets a reference to the namespace.
pub fn namespace(&self) -> &String {
&self.namespace
}

/// Gets a mutable reference to the namespace.
pub fn namespace_mut(&mut self) -> &mut String {
&mut self.namespace
}
}
5 changes: 5 additions & 0 deletions packages/apalis-sql/src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ impl<T: Serialize + DeserializeOwned> MysqlStorage<T> {
pub fn codec(&self) -> &BoxCodec<T, serde_json::Value> {
&self.codec
}

/// Get the config used by the storage
pub fn get_config(&self) -> &Config {
&self.config
}
}

impl<T: DeserializeOwned + Send + Unpin + Sync + 'static> MysqlStorage<T> {
Expand Down
5 changes: 5 additions & 0 deletions packages/apalis-sql/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ impl<T: Serialize + DeserializeOwned> SqliteStorage<T> {
pub fn codec(&self) -> &SqliteCodec<T> {
&self.codec
}

/// Get the config used by the storage
pub fn get_config(&self) -> &Config {
&self.config
}
}

async fn fetch_next(
Expand Down
Loading