Use crono types instead of unsigned integers for time periods.
This commit is contained in:
+11
-11
@@ -39,10 +39,9 @@ fn download_checker() -> Result<(), DataError> {
|
||||
}
|
||||
|
||||
/// Delete watched `episodes` that have exceded their liftime after played.
|
||||
fn played_cleaner(age: u32) -> Result<(), DataError> {
|
||||
let age = age as i32;
|
||||
fn played_cleaner(cleanup_date: DateTime<Utc>) -> Result<(), DataError> {
|
||||
let mut episodes = dbqueries::get_played_cleaner_episodes()?;
|
||||
let now_utc = Utc::now().timestamp() as i32 - age;
|
||||
let now_utc = cleanup_date.timestamp() as i32;
|
||||
|
||||
episodes
|
||||
.par_iter_mut()
|
||||
@@ -91,10 +90,10 @@ fn delete_local_content(ep: &mut EpisodeCleanerQuery) -> Result<(), DataError> {
|
||||
///
|
||||
/// Runs a cleaner for played Episode's that are pass the lifetime limit and
|
||||
/// scheduled for removal.
|
||||
pub fn checkup(cleanup_age: u32) -> Result<(), DataError> {
|
||||
pub fn checkup(cleanup_date: DateTime<Utc>) -> Result<(), DataError> {
|
||||
info!("Running database checks.");
|
||||
download_checker()?;
|
||||
played_cleaner(cleanup_age)?;
|
||||
played_cleaner(cleanup_date)?;
|
||||
info!("Checks completed.");
|
||||
Ok(())
|
||||
}
|
||||
@@ -181,6 +180,7 @@ mod tests {
|
||||
|
||||
use self::tempdir::TempDir;
|
||||
use super::*;
|
||||
use chrono::Duration;
|
||||
|
||||
use database::truncate_db;
|
||||
use models::NewEpisodeBuilder;
|
||||
@@ -260,14 +260,14 @@ mod tests {
|
||||
fn test_played_cleaner_expired() {
|
||||
let _tmp_dir = helper_db();
|
||||
let mut episode = dbqueries::get_episode_from_pk("foo_bar", 0).unwrap();
|
||||
let now_utc = Utc::now().timestamp() as i32;
|
||||
let epoch = now_utc - 200_000;
|
||||
let cleanup_date = Utc::now() - Duration::seconds(1000);
|
||||
let epoch = cleanup_date.timestamp() as i32 - 1;
|
||||
episode.set_played(Some(epoch));
|
||||
episode.save().unwrap();
|
||||
let valid_path = episode.local_uri().unwrap().to_owned();
|
||||
|
||||
// This should delete the file
|
||||
played_cleaner(172_800).unwrap();
|
||||
played_cleaner(cleanup_date).unwrap();
|
||||
assert_eq!(Path::new(&valid_path).exists(), false);
|
||||
}
|
||||
|
||||
@@ -275,14 +275,14 @@ mod tests {
|
||||
fn test_played_cleaner_none() {
|
||||
let _tmp_dir = helper_db();
|
||||
let mut episode = dbqueries::get_episode_from_pk("foo_bar", 0).unwrap();
|
||||
let now_utc = Utc::now().timestamp() as i32;
|
||||
let epoch = now_utc - 20_000;
|
||||
let cleanup_date = Utc::now() - Duration::seconds(1000);
|
||||
let epoch = cleanup_date.timestamp() as i32 + 1;
|
||||
episode.set_played(Some(epoch));
|
||||
episode.save().unwrap();
|
||||
let valid_path = episode.local_uri().unwrap().to_owned();
|
||||
|
||||
// This should not delete the file
|
||||
played_cleaner(172_800).unwrap();
|
||||
played_cleaner(cleanup_date).unwrap();
|
||||
assert_eq!(Path::new(&valid_path).exists(), true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user