mirror of
https://github.com/moghtech/komodo.git
synced 2026-09-10 16:01:20 +00:00
any sync error shows up in log
This commit is contained in:
@@ -73,6 +73,7 @@ pub trait ResourceSync: MonitorResource + Sized {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut has_error = false;
|
||||
let mut log =
|
||||
format!("running updates on {}s", Self::resource_type());
|
||||
|
||||
@@ -89,6 +90,7 @@ pub trait ResourceSync: MonitorResource + Sized {
|
||||
{
|
||||
Ok(resource) => resource.id,
|
||||
Err(e) => {
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to create {} '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -98,13 +100,20 @@ pub trait ResourceSync: MonitorResource + Sized {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
run_update_tags::<Self>(id.clone(), &name, tags, &mut log)
|
||||
.await;
|
||||
run_update_tags::<Self>(
|
||||
id.clone(),
|
||||
&name,
|
||||
tags,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
run_update_description::<Self>(
|
||||
id,
|
||||
&name,
|
||||
description,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
log.push_str(&format!(
|
||||
@@ -134,13 +143,20 @@ pub trait ResourceSync: MonitorResource + Sized {
|
||||
&name,
|
||||
description,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
if update_tags {
|
||||
run_update_tags::<Self>(id.clone(), &name, tags, &mut log)
|
||||
.await;
|
||||
run_update_tags::<Self>(
|
||||
id.clone(),
|
||||
&name,
|
||||
tags,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
if !resource.config.is_none() {
|
||||
@@ -151,6 +167,7 @@ pub trait ResourceSync: MonitorResource + Sized {
|
||||
)
|
||||
.await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to update config on {} '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -173,6 +190,7 @@ pub trait ResourceSync: MonitorResource + Sized {
|
||||
if let Err(e) =
|
||||
crate::resource::delete::<Self>(&resource, sync_user()).await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to delete {} '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -190,10 +208,12 @@ pub trait ResourceSync: MonitorResource + Sized {
|
||||
}
|
||||
}
|
||||
|
||||
Some(Log::simple(
|
||||
&format!("Update {}s", Self::resource_type()),
|
||||
log,
|
||||
))
|
||||
let stage = format!("Update {}s", Self::resource_type());
|
||||
Some(if has_error {
|
||||
Log::error(&stage, log)
|
||||
} else {
|
||||
Log::simple(&stage, log)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,6 +443,7 @@ pub async fn run_update_tags<Resource: ResourceSync>(
|
||||
name: &str,
|
||||
tags: Vec<String>,
|
||||
log: &mut String,
|
||||
has_error: &mut bool,
|
||||
) {
|
||||
// Update tags
|
||||
if let Err(e) = State
|
||||
@@ -435,6 +456,7 @@ pub async fn run_update_tags<Resource: ResourceSync>(
|
||||
)
|
||||
.await
|
||||
{
|
||||
*has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to update tags on {} '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -457,6 +479,7 @@ pub async fn run_update_description<Resource: ResourceSync>(
|
||||
name: &str,
|
||||
description: String,
|
||||
log: &mut String,
|
||||
has_error: &mut bool,
|
||||
) {
|
||||
if let Err(e) = State
|
||||
.resolve(
|
||||
@@ -468,6 +491,7 @@ pub async fn run_update_description<Resource: ResourceSync>(
|
||||
)
|
||||
.await
|
||||
{
|
||||
*has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to update description on {} '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
|
||||
@@ -317,6 +317,7 @@ impl ResourceSync for Procedure {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut has_error = false;
|
||||
let mut log =
|
||||
format!("running updates on {}s", Self::resource_type());
|
||||
|
||||
@@ -324,6 +325,7 @@ impl ResourceSync for Procedure {
|
||||
if let Err(e) =
|
||||
crate::resource::delete::<Procedure>(&name, sync_user()).await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"{}: failed to delete {} '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -342,10 +344,12 @@ impl ResourceSync for Procedure {
|
||||
}
|
||||
|
||||
if to_update.is_empty() && to_create.is_empty() {
|
||||
return Some(Log::simple(
|
||||
&format!("Update {}s", Self::resource_type()),
|
||||
log,
|
||||
));
|
||||
let stage = "Update Procedures";
|
||||
return Some(if has_error {
|
||||
Log::error(stage, log)
|
||||
} else {
|
||||
Log::simple(stage, log)
|
||||
});
|
||||
}
|
||||
|
||||
for i in 0..10 {
|
||||
@@ -367,6 +371,7 @@ impl ResourceSync for Procedure {
|
||||
&name,
|
||||
description,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -376,6 +381,7 @@ impl ResourceSync for Procedure {
|
||||
&name,
|
||||
tags,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -388,9 +394,9 @@ impl ResourceSync for Procedure {
|
||||
.await
|
||||
{
|
||||
if i == 9 {
|
||||
log.push('\n');
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"{}: failed to update {} '{}' | {e:#}",
|
||||
"\n{}: failed to update {} '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
Self::resource_type(),
|
||||
bold(&name)
|
||||
@@ -400,9 +406,8 @@ impl ResourceSync for Procedure {
|
||||
}
|
||||
}
|
||||
|
||||
log.push('\n');
|
||||
log.push_str(&format!(
|
||||
"{}: {} '{}' updated",
|
||||
"\n{}: {} '{}' updated",
|
||||
muted("INFO"),
|
||||
Self::resource_type(),
|
||||
bold(&name)
|
||||
@@ -428,9 +433,9 @@ impl ResourceSync for Procedure {
|
||||
Ok(resource) => resource.id,
|
||||
Err(e) => {
|
||||
if i == 9 {
|
||||
log.push('\n');
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"{}: failed to create {} '{}' | {e:#}",
|
||||
"\n{}: failed to create {} '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
Self::resource_type(),
|
||||
bold(&name)
|
||||
@@ -444,6 +449,7 @@ impl ResourceSync for Procedure {
|
||||
&name,
|
||||
tags,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
run_update_description::<Procedure>(
|
||||
@@ -451,6 +457,7 @@ impl ResourceSync for Procedure {
|
||||
&name,
|
||||
description,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
log.push_str(&format!(
|
||||
@@ -465,8 +472,12 @@ impl ResourceSync for Procedure {
|
||||
to_create.retain(|resource| !to_pull.contains(&resource.name));
|
||||
|
||||
if to_update.is_empty() && to_create.is_empty() {
|
||||
// info!("all procedures synced");
|
||||
return Some(Log::simple("Update Procedures", log));
|
||||
let stage = "Update Procedures";
|
||||
return Some(if has_error {
|
||||
Log::error(stage, log)
|
||||
} else {
|
||||
Log::simple(stage, log)
|
||||
});
|
||||
}
|
||||
}
|
||||
warn!("procedure sync loop exited after max iterations");
|
||||
|
||||
@@ -477,6 +477,7 @@ pub async fn run_updates(
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut has_error = false;
|
||||
let mut log = String::from("running updates on UserGroups");
|
||||
|
||||
// Create the non-existant user groups
|
||||
@@ -491,6 +492,7 @@ pub async fn run_updates(
|
||||
)
|
||||
.await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to create user group '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -506,12 +508,18 @@ pub async fn run_updates(
|
||||
))
|
||||
};
|
||||
|
||||
set_users(user_group.name.clone(), user_group.users, &mut log)
|
||||
.await;
|
||||
set_users(
|
||||
user_group.name.clone(),
|
||||
user_group.users,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
run_update_permissions(
|
||||
user_group.name,
|
||||
user_group.permissions,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -524,14 +532,20 @@ pub async fn run_updates(
|
||||
} in to_update
|
||||
{
|
||||
if update_users {
|
||||
set_users(user_group.name.clone(), user_group.users, &mut log)
|
||||
.await;
|
||||
set_users(
|
||||
user_group.name.clone(),
|
||||
user_group.users,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
if update_permissions {
|
||||
run_update_permissions(
|
||||
user_group.name,
|
||||
user_group.permissions,
|
||||
&mut log,
|
||||
&mut has_error,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -545,6 +559,7 @@ pub async fn run_updates(
|
||||
)
|
||||
.await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to delete user group '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -560,13 +575,19 @@ pub async fn run_updates(
|
||||
}
|
||||
}
|
||||
|
||||
Some(Log::simple("Update UserGroups", log))
|
||||
let stage = "Update UserGroups";
|
||||
Some(if has_error {
|
||||
Log::error(stage, log)
|
||||
} else {
|
||||
Log::simple(stage, log)
|
||||
})
|
||||
}
|
||||
|
||||
async fn set_users(
|
||||
user_group: String,
|
||||
users: Vec<String>,
|
||||
log: &mut String,
|
||||
has_error: &mut bool,
|
||||
) {
|
||||
if let Err(e) = State
|
||||
.resolve(
|
||||
@@ -578,6 +599,7 @@ async fn set_users(
|
||||
)
|
||||
.await
|
||||
{
|
||||
*has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to set users in group {} | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -597,6 +619,7 @@ async fn run_update_permissions(
|
||||
user_group: String,
|
||||
permissions: Vec<PermissionToml>,
|
||||
log: &mut String,
|
||||
has_error: &mut bool,
|
||||
) {
|
||||
for PermissionToml { target, level } in permissions {
|
||||
if let Err(e) = State
|
||||
@@ -610,6 +633,7 @@ async fn run_update_permissions(
|
||||
)
|
||||
.await
|
||||
{
|
||||
*has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to set permssion in group {} | target: {target:?} | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
|
||||
@@ -184,6 +184,7 @@ pub async fn run_updates(
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut has_error = false;
|
||||
let mut log = String::from("running updates on Variables");
|
||||
|
||||
for variable in to_create {
|
||||
@@ -198,6 +199,7 @@ pub async fn run_updates(
|
||||
)
|
||||
.await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to create variable '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -230,6 +232,7 @@ pub async fn run_updates(
|
||||
)
|
||||
.await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to update variable value for '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -255,6 +258,7 @@ pub async fn run_updates(
|
||||
)
|
||||
.await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to update variable description for '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -281,6 +285,7 @@ pub async fn run_updates(
|
||||
)
|
||||
.await
|
||||
{
|
||||
has_error = true;
|
||||
log.push_str(&format!(
|
||||
"\n{}: failed to delete variable '{}' | {e:#}",
|
||||
colored("ERROR", "red"),
|
||||
@@ -296,5 +301,10 @@ pub async fn run_updates(
|
||||
}
|
||||
}
|
||||
|
||||
Some(Log::simple("Update Variables", log))
|
||||
let stage = "Update Variables";
|
||||
Some(if has_error {
|
||||
Log::error(stage, log)
|
||||
} else {
|
||||
Log::simple(stage, log)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user