sync working

This commit is contained in:
mbecker20
2024-05-06 01:44:20 -07:00
parent 3d9da97d7b
commit aad971a599
3 changed files with 27 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
[[deployment]]
name = "monitor-proxy"
description = ""
description = "An NGINX proxy for mogh.tech"
tags = ["monitor"]
[deployment.config]

View File

@@ -7,7 +7,7 @@ use monitor_client::{
builder::BuilderListItem, deployment::DeploymentListItem,
procedure::ProcedureListItem, repo::RepoListItem,
server::ServerListItem, server_template::ServerTemplateListItem,
user::User, user_group::UserGroup,
tag::Tag, user::User, user_group::UserGroup,
},
};
@@ -258,7 +258,7 @@ pub fn name_to_user_group() -> &'static HashMap<String, UserGroup> {
futures::executor::block_on(
monitor_client().read(read::ListUserGroups::default()),
)
.expect("failed to get procedures from monitor")
.expect("failed to get user groups from monitor")
.into_iter()
.map(|user_group| (user_group.name.clone(), user_group))
.collect()
@@ -272,9 +272,22 @@ pub fn id_to_user() -> &'static HashMap<String, User> {
futures::executor::block_on(
monitor_client().read(read::ListUsers::default()),
)
.expect("failed to get procedures from monitor")
.expect("failed to get users from monitor")
.into_iter()
.map(|user| (user.id.clone(), user))
.collect()
})
}
pub fn id_to_tag() -> &'static HashMap<String, Tag> {
static ID_TO_TAG: OnceLock<HashMap<String, Tag>> = OnceLock::new();
ID_TO_TAG.get_or_init(|| {
futures::executor::block_on(
monitor_client().read(read::ListTags::default()),
)
.expect("failed to get tags from monitor")
.into_iter()
.map(|tag| (tag.id.clone(), tag))
.collect()
})
}

View File

@@ -11,7 +11,7 @@ use monitor_client::{
};
use partial_derive2::MaybeNone;
use crate::{cli_args, monitor_client};
use crate::{cli_args, maps::id_to_tag, monitor_client};
pub mod alerter;
pub mod build;
@@ -84,11 +84,19 @@ pub trait ResourceSync {
Self::minimize_update(original.config, resource.config)
.await?;
let original_tags = original
.tags
.iter()
.filter_map(|id| {
id_to_tag().get(id).map(|t| t.name.clone())
})
.collect::<Vec<_>>();
// Only try to update if there are any fields to update,
// or a change to tags / description
if !resource.config.is_none()
|| resource.description != original.description
|| resource.tags != original.tags
|| resource.tags != original_tags
{
to_update.push((id, resource));
}