Skip to content

Commit

Permalink
omdb could interpret status of blueprint tasks (#6440)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco authored Aug 27, 2024
1 parent 6207e19 commit 758818a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
56 changes: 56 additions & 0 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,62 @@ fn print_task_details(bgtask: &BackgroundTask, details: &serde_json::Value) {
}
}
}
} else if name == "blueprint_loader" {
#[derive(Deserialize)]
struct BlueprintLoaderStatus {
target_id: Uuid,
time_created: DateTime<Utc>,
status: String,
enabled: bool,
}

match serde_json::from_value::<BlueprintLoaderStatus>(details.clone()) {
Err(error) => eprintln!(
"warning: failed to interpret task details: {:?}: {:?}",
error, details
),
Ok(status) => {
println!(" target blueprint: {}", status.target_id);
println!(
" execution: {}",
if status.enabled { "enabled" } else { "disabled" }
);
println!(
" created at: {}",
humantime::format_rfc3339_millis(
status.time_created.into()
)
);
println!(" status: {}", status.status);
}
}
} else if name == "blueprint_executor" {
#[derive(Deserialize)]
struct BlueprintExecutorStatus {
target_id: Uuid,
enabled: bool,
errors: Option<Vec<String>>,
}

match serde_json::from_value::<BlueprintExecutorStatus>(details.clone())
{
Err(error) => eprintln!(
"warning: failed to interpret task details: {:?}: {:?}",
error, details
),
Ok(status) => {
println!(" target blueprint: {}", status.target_id);
println!(
" execution: {}",
if status.enabled { "enabled" } else { "disabled" }
);
let errors = status.errors.as_deref().unwrap_or(&[]);
println!(" errors: {}", errors.len());
for (i, e) in errors.iter().enumerate() {
println!(" error {}: {}", i, e);
}
}
}
} else {
println!(
"warning: unknown background task: {:?} \
Expand Down
8 changes: 6 additions & 2 deletions nexus/src/app/background/tasks/blueprint_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl BlueprintExecutor {
"target_id" => %blueprint.id);
return json!({
"target_id": blueprint.id.to_string(),
"error": "blueprint disabled"
"enabled": false,
});
}

Expand Down Expand Up @@ -111,6 +111,7 @@ impl BlueprintExecutor {

json!({
"target_id": blueprint.id.to_string(),
"enabled": true,
"needs_saga_recovery": needs_saga_recovery,
})
}
Expand All @@ -119,6 +120,7 @@ impl BlueprintExecutor {
errors.into_iter().map(|e| format!("{:#}", e)).collect();
json!({
"target_id": blueprint.id.to_string(),
"enabled": true,
"errors": errors
})
}
Expand Down Expand Up @@ -316,6 +318,7 @@ mod test {
value,
json!({
"target_id": blueprint_id,
"enabled": true,
"needs_saga_recovery": false,
})
);
Expand Down Expand Up @@ -410,6 +413,7 @@ mod test {
value,
json!({
"target_id": blueprint.1.id.to_string(),
"enabled": true,
"needs_saga_recovery": false,
})
);
Expand All @@ -427,7 +431,7 @@ mod test {
assert_eq!(
value,
json!({
"error": "blueprint disabled",
"enabled": false,
"target_id": blueprint.1.id.to_string()
})
);
Expand Down
9 changes: 7 additions & 2 deletions nexus/src/app/background/tasks/blueprint_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl BackgroundTask for TargetBlueprintLoader {
};

// Decide what to do with the new blueprint
let enabled = new_bp_target.enabled;
let Some((old_bp_target, old_blueprint)) = self.last.as_deref()
else {
// We've found a target blueprint for the first time.
Expand All @@ -97,6 +98,7 @@ impl BackgroundTask for TargetBlueprintLoader {
"time_created": time_created,
"time_found": chrono::Utc::now(),
"status": "first target blueprint",
"enabled": enabled,
});
};

Expand All @@ -116,7 +118,8 @@ impl BackgroundTask for TargetBlueprintLoader {
"target_id": target_id,
"time_created": time_created,
"time_found": chrono::Utc::now(),
"status": "target blueprint updated"
"status": "target blueprint updated",
"enabled": enabled,
})
} else {
// The new target id matches the old target id
Expand Down Expand Up @@ -159,6 +162,7 @@ impl BackgroundTask for TargetBlueprintLoader {
"time_created": time_created,
"time_found": chrono::Utc::now(),
"status": format!("target blueprint {status}"),
"enabled": enabled,
})
} else {
// We found a new target blueprint that exactly
Expand All @@ -173,7 +177,8 @@ impl BackgroundTask for TargetBlueprintLoader {
json!({
"target_id": target_id,
"time_created": time_created,
"status": "target blueprint unchanged"
"status": "target blueprint unchanged",
"enabled": enabled,
})
}
}
Expand Down

0 comments on commit 758818a

Please sign in to comment.