Skip to content

Commit

Permalink
add field dateCreated ini holoport_status for a TTL index
Browse files Browse the repository at this point in the history
  • Loading branch information
peeech committed Oct 20, 2023
1 parent 6a0805d commit 33c7d40
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use mongodb::bson::{self, doc, Document};
use mongodb::bson::{self, doc, Document, DateTime};
use mongodb::options::AggregateOptions;
use mongodb::{Client, Collection};
use rocket::futures::TryStreamExt;
Expand Down Expand Up @@ -45,12 +45,12 @@ pub async fn ping_database(db: &Client) -> Result<String> {
}

// Delete from host_statistics.holoport_status documents with
// timestamp field older than 30 days. Used for database cleanup
// timestamp field older than 14 days. Used for database cleanup
pub async fn cleanup_database(db: &Client) -> Result<String, ApiError> {
let hp_status: Collection<HostStats> =
db.database("host_statistics").collection("holoport_status");

let cutoff_ms = match get_cutoff_timestamp(30 * 24) {
let cutoff_ms = match get_cutoff_timestamp(14 * 24) {
Some(x) => x,
None => return Err(ApiError::BadRequest(HOURS_TOO_LARGE)),
};
Expand Down Expand Up @@ -271,6 +271,7 @@ pub async fn add_holoport_status(hs: HostStats, db: &Client) -> Result<(), ApiEr
"hposAppList": hpos_app_list,
"channelVersion": hs.channel_version,
"hposVersion": hs.hpos_version,
"dateCreated": DateTime::now(), // Field of bson type Date required for TTL index
};
match hp_status.insert_one(val, None).await {
Ok(_) => Ok(()),
Expand Down

0 comments on commit 33c7d40

Please sign in to comment.