Skip to content

Commit

Permalink
fix: review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hanadi92 committed Jan 23, 2024
1 parent 4d05290 commit 20a69a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/background_updates/run/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use ruma::{
api::{request, response, Metadata},
metadata,
serde::StringEnum,
};

const METADATA: Metadata = metadata! {
Expand All @@ -17,11 +18,7 @@ const METADATA: Metadata = metadata! {
#[request]
pub struct Request {
/// A string which job to run
///
/// Valid values are:
/// populate_stats_process_rooms
/// regenerate_directory
pub job_name: String,
pub job_name: JobName,
}

#[response]
Expand All @@ -30,7 +27,7 @@ pub struct Response {}

impl Request {
/// Creates a `Request` with the given `job_name` value.
pub fn new(job_name: String) -> Self {
pub fn new(job_name: JobName) -> Self {
Self { job_name }
}
}
Expand All @@ -42,9 +39,21 @@ impl Response {
}
}

#[derive(Clone, PartialEq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
pub enum JobName {
/// Recalculate the stats for all rooms.
PopulateStatsProcessRooms,
/// Recalculate the user directory if it is stale or out of sync
RegenerateDirectory,

#[doc(hidden)]
_Custom(crate::PrivOwnedStr),
}

#[test]
fn test_run_background_updates() {
let job_name = "test-job-name".to_string();
let job_name = JobName::PopulateStatsProcessRooms;
// Check create request
let request = Request::new(job_name.clone());
assert_eq!(request.job_name, job_name);
Expand Down
2 changes: 1 addition & 1 deletion src/background_updates/status/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct CurrentUpdate {
pub name: String,

/// Total number of processed "items"
pub total_item_count: i32,
pub total_item_count: u64,

/// Runtime of background process, not including sleeping time
pub total_duration_ms: f64,
Expand Down

0 comments on commit 20a69a6

Please sign in to comment.