Skip to content

Commit

Permalink
Remove backup::schedule_periodic
Browse files Browse the repository at this point in the history
  • Loading branch information
minshao authored and msk committed Feb 13, 2024
1 parent 37cc73f commit 037bd09
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- To ensure data integrity and avoid potential data loss, users currently
utilizing review-database versions below 0.24.0 must migrate to version
0.24.0 before proceeding with any further migrations.
- The `backup::schedule_periodic` function has been permanently removed. This
decision has been made to streamline and focus on providing precise abstractions
for database operations. Users are advised to update their codebase accordingly
and leverage alternative methods for scheduling periodic backups.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "review-database"
version = "0.25.0-alpha.5"
version = "0.25.0-alpha.6"
edition = "2021"

[dependencies]
Expand Down
35 changes: 2 additions & 33 deletions src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::Store;
use anyhow::Result;
use chrono::{DateTime, TimeZone, Utc};
use rocksdb::backup::BackupEngineInfo;
use std::{sync::Arc, time::Duration};
use tokio::sync::{Notify, RwLock};
use std::sync::Arc;
use tokio::sync::RwLock;
use tracing::{info, warn};

#[allow(clippy::module_name_repetitions)]
Expand All @@ -25,37 +25,6 @@ impl From<BackupEngineInfo> for BackupInfo {
}
}

/// Schedules periodic database backups.
#[allow(clippy::module_name_repetitions)]
pub async fn schedule_periodic(
store: Arc<RwLock<Store>>,
schedule: (Duration, Duration),
backups_to_keep: u32,
stop: Arc<Notify>,
) {
use tokio::time::{sleep, Instant};

let (init, duration) = schedule;
let sleep = sleep(init);
tokio::pin!(sleep);

loop {
tokio::select! {
() = &mut sleep => {
sleep.as_mut().reset(Instant::now() + duration);
let _res = create(&store, false, backups_to_keep);
}
() = stop.notified() => {
info!("creating a database backup before shutdown");
let _res = create(&store, false, backups_to_keep);
stop.notify_one();
return;
}

}
}
}

/// Creates a new database backup, keeping the specified number of backups.
///
/// # Errors
Expand Down
2 changes: 1 addition & 1 deletion src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use tracing::info;
/// // the database format won't be changed in the future alpha or beta versions.
/// const COMPATIBLE_VERSION: &str = ">=0.5.0-alpha.2,<=0.5.0-alpha.4";
/// ```
const COMPATIBLE_VERSION_REQ: &str = ">=0.24.0,<=0.25.0-alpha.5";
const COMPATIBLE_VERSION_REQ: &str = ">=0.24.0,<=0.25.0-alpha.6";

/// Migrates data exists in `PostgresQL` to Rocksdb if necessary.
///
Expand Down

0 comments on commit 037bd09

Please sign in to comment.