first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use diesel::result::Error;
|
||||
use diesel::{Connection, QueryDsl, RunQueryDsl, SqliteConnection};
|
||||
use persistence::model::NewCloudObjectsRefresh;
|
||||
use persistence::schema;
|
||||
|
||||
pub fn record_time_of_next_refresh(
|
||||
conn: &mut SqliteConnection,
|
||||
timestamp: DateTime<Utc>,
|
||||
) -> Result<(), Error> {
|
||||
use schema::cloud_objects_refreshes::dsl::*;
|
||||
let refresh = NewCloudObjectsRefresh {
|
||||
time_of_next_refresh: timestamp.naive_utc(),
|
||||
};
|
||||
conn.transaction::<(), Error, _>(|conn| {
|
||||
diesel::delete(cloud_objects_refreshes).execute(conn)?;
|
||||
diesel::insert_into(cloud_objects_refreshes)
|
||||
.values(refresh)
|
||||
.execute(conn)?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn read_time_of_next_force_object_refresh(
|
||||
conn: &mut SqliteConnection,
|
||||
) -> Result<Option<DateTime<Utc>>, Error> {
|
||||
// Find the smallest refresh timestamp to pass into CloudModel.
|
||||
Ok(cloud_objects_refreshes
|
||||
.select(time_of_next_refresh)
|
||||
.load::<NaiveDateTime>(conn)?
|
||||
.into_iter()
|
||||
.map(|refresh| refresh.and_utc())
|
||||
.min())
|
||||
}
|
||||
Reference in New Issue
Block a user