Skip to content

Commit

Permalink
Add download_semi_models GraphQL api
Browse files Browse the repository at this point in the history
  • Loading branch information
kimhanbeom committed Dec 7, 2023
1 parent ca6a320 commit 7a2dc91
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/graphql/semi_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ impl SemiModelMutation {
Ok(true)
}

/// Download semi-supervised models using model name , Returns true if the deletion was successful.
#[graphql(guard = "RoleGuard::new(Role::SystemAdministrator)
.or(RoleGuard::new(Role::SecurityAdministrator))")]
async fn download_semi_models(
&self,
ctx: &Context<'_>,
input_models: Vec<SemiModel>,
) -> Result<bool> {
let store = crate::graphql::get_store(ctx).await?;
let map = store.semi_models_map();

let iter = map.iter_forward()?;
for (key, _) in iter {
map.delete(&key)?;
}
for model in input_models {
let key = model.model_name.clone();
let value = bincode::serialize::<SemiModelValue>(&(model, Utc::now()))?;
map.put(key.as_bytes(), &value)?;
}
Ok(true)
}

/// Broadcast the semi-supervised model list to all Hogs.
#[graphql(guard = "RoleGuard::new(Role::SystemAdministrator)
.or(RoleGuard::new(Role::SecurityAdministrator))")]
Expand Down

0 comments on commit 7a2dc91

Please sign in to comment.