Skip to content

Commit

Permalink
add sqlite max connections as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
magnickolas committed Dec 19, 2024
1 parent 74d6fd8 commit 31709d7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ async fn deadline_from_datetime(dt: NaiveDateTime) -> Instant {
Instant::now() + duration
}

/// Periodically (every second) check for new reminders.
/// Send and delete one-time reminders if time has come.
/// Send cron reminders if time has come and update next reminder time.
/// Wait for the next reminder to send or some change in the database.
/// Send and update/delete reminders.
async fn poll_reminders(db: Arc<Database>, bot: Bot) {
const DEFAULT_CHECK_INTERVAL: TimeDelta = TimeDelta::seconds(60);

Expand Down
9 changes: 9 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ pub(crate) struct Cli {
pub(crate) database: PathBuf,
#[arg(short, long, value_name = "BOT TOKEN", env = "BOT_TOKEN")]
pub(crate) token: String,
#[arg(
short,
long,
env = "SQLITE_MAX_CONNECTIONS",
value_name = "NUMBER",
help = "Maximum number of connections to the SQLite database",
default_value = "1"
)]
pub(crate) sqlite_max_connections: u32,
}

pub(crate) fn parse_args() -> Cli {
Expand Down
3 changes: 2 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::Path;

use crate::cli::CLI;
use crate::entity::{cron_reminder, reminder, user_timezone};
use crate::generic_reminder;
use crate::migration::{DbErr, Migrator, MigratorTrait};
Expand Down Expand Up @@ -45,7 +46,7 @@ impl From<std::io::Error> for Error {
async fn get_db_pool(db_path: &Path) -> Result<DatabaseConnection, Error> {
let db_str = format!("sqlite:{}?mode=rwc", db_path.display());
let mut opts = ConnectOptions::new(&db_str);
opts.max_connections(100);
opts.max_connections(CLI.sqlite_max_connections);
let pool = SeaOrmDatabase::connect(opts).await?;
Ok(pool)
}
Expand Down

0 comments on commit 31709d7

Please sign in to comment.