pub struct TaskResults { /* private fields */ }Expand description
Results of a task execution, including timing, host outcomes, and nested sub-task results.
TaskResults captures the complete execution state of a task across multiple hosts,
including timing information, a summary, per-host results, and any sub-tasks that were
executed as part of this task. This structure forms a tree where each task can contain
results for multiple hosts and multiple sub-tasks, allowing for hierarchical task execution
tracking.
§Fields
task_name- The name of the task that was executed.started_at- The timestamp when the task execution started, if available.finished_at- The timestamp when the task execution finished, if available.duration_ms- The duration of the task execution in milliseconds, if available.summary- An optional summary message describing the overall task execution.hosts- A map of hostname toHostTaskResult, containing the execution result for each host.sub_tasks- A map of sub-task name toTaskResults, containing results for any nested tasks.
§Example
use genja_core::task::{TaskResults, HostTaskResult, TaskSuccess};
use std::time::SystemTime;
// Create a new task results container
let mut results = TaskResults::new("deploy_config")
.with_started_at(SystemTime::now())
.with_summary("Deploying configuration to network devices");
// Add results for individual hosts
results.insert_host_result(
"router1",
HostTaskResult::passed(
TaskSuccess::new()
.with_changed(true)
.with_summary("Configuration deployed successfully")
)
);
results.insert_host_result(
"router2",
HostTaskResult::skipped_with_reason("Device in maintenance mode")
);
// Create and add sub-task results
let mut validation_results = TaskResults::new("validate_config");
validation_results.insert_host_result(
"router1",
HostTaskResult::passed(TaskSuccess::new())
);
results.insert_sub_task("validate_config", validation_results);
// Query results
assert_eq!(results.task_name(), "deploy_config");
assert_eq!(results.passed_hosts().len(), 1);
assert!(results.sub_task("validate_config").is_some());Implementations§
Source§impl TaskResults
impl TaskResults
Sourcepub fn new(task_name: impl Into<String>) -> Self
pub fn new(task_name: impl Into<String>) -> Self
Creates a new TaskResults instance with the specified task name.
This constructor initializes a TaskResults with the given task name and empty
collections for hosts and sub-tasks. All timing and summary fields are set to None.
§Parameters
task_name- The name of the task. Can be any type that implementsInto<String>, such as&str,String, or other string-like types.
§Returns
A new TaskResults instance with the specified task name and default values for all
other fields.
Sourcepub fn with_started_at(self, started_at: SystemTime) -> Self
pub fn with_started_at(self, started_at: SystemTime) -> Self
Sourcepub fn with_finished_at(self, finished_at: SystemTime) -> Self
pub fn with_finished_at(self, finished_at: SystemTime) -> Self
Sourcepub fn with_duration_ms(self, duration_ms: u128) -> Self
pub fn with_duration_ms(self, duration_ms: u128) -> Self
Sets the task execution duration in milliseconds.
This is a builder method that consumes self and returns the modified instance,
allowing for method chaining.
§Parameters
duration_ms- The duration of the task execution in milliseconds.
§Returns
The modified TaskResults instance with the duration set.
Sourcepub fn with_duration_ns(self, duration_ns: u128) -> Self
pub fn with_duration_ns(self, duration_ns: u128) -> Self
Sets the task execution duration in nanoseconds.
Sourcepub fn with_summary(self, summary: impl Into<String>) -> Self
pub fn with_summary(self, summary: impl Into<String>) -> Self
Sets a summary message describing the task execution.
This is a builder method that consumes self and returns the modified instance,
allowing for method chaining.
§Parameters
summary- A human-readable summary message. Can be any type that implementsInto<String>, such as&str,String, or other string-like types.
§Returns
The modified TaskResults instance with the summary set.
Sourcepub fn merge(&mut self, other: TaskResults)
pub fn merge(&mut self, other: TaskResults)
Merges another result tree for the same task into this one.
Host results are inserted directly and sub-task trees are merged recursively. Aggregate timing is widened to cover the full execution window across both result trees.
Sourcepub fn started_at(&self) -> Option<SystemTime>
pub fn started_at(&self) -> Option<SystemTime>
Returns the task execution start timestamp, if available.
§Returns
Some(SystemTime) if the start timestamp was set, None otherwise.
Sourcepub fn finished_at(&self) -> Option<SystemTime>
pub fn finished_at(&self) -> Option<SystemTime>
Returns the task execution finish timestamp, if available.
§Returns
Some(SystemTime) if the finish timestamp was set, None otherwise.
Sourcepub fn duration_ms(&self) -> Option<u128>
pub fn duration_ms(&self) -> Option<u128>
Returns the task execution duration in milliseconds, if available.
§Returns
Some(u128) if the duration was set, None otherwise.
Sourcepub fn duration_ns(&self) -> Option<u128>
pub fn duration_ns(&self) -> Option<u128>
Returns the task execution duration in nanoseconds, if available.
Sourcepub fn started_at_display(&self) -> Option<String>
pub fn started_at_display(&self) -> Option<String>
Returns the task execution start timestamp in RFC 3339 format, if available.
Sourcepub fn finished_at_display(&self) -> Option<String>
pub fn finished_at_display(&self) -> Option<String>
Returns the task execution finish timestamp in RFC 3339 format, if available.
Sourcepub fn duration_display(&self) -> Option<String>
pub fn duration_display(&self) -> Option<String>
Returns the task execution duration in a human-readable format, if available.
Sourcepub fn to_json_string(&self) -> Result<String, Error>
pub fn to_json_string(&self) -> Result<String, Error>
Serializes task results as compact human-readable JSON.
Sourcepub fn to_pretty_json_string(&self) -> Result<String, Error>
pub fn to_pretty_json_string(&self) -> Result<String, Error>
Serializes task results as pretty-printed human-readable JSON.
Sourcepub fn to_raw_json_string(&self) -> Result<String, Error>
pub fn to_raw_json_string(&self) -> Result<String, Error>
Serializes task results as compact raw JSON using the struct’s default serde representation.
Sourcepub fn to_raw_pretty_json_string(&self) -> Result<String, Error>
pub fn to_raw_pretty_json_string(&self) -> Result<String, Error>
Serializes task results as pretty-printed raw JSON using the struct’s default serde representation.
Sourcepub fn summary(&self) -> Option<&str>
pub fn summary(&self) -> Option<&str>
Returns the task summary message, if available.
§Returns
Some(&str) if a summary was set, None otherwise.
Sourcepub fn insert_host_result<K>(&mut self, hostname: K, result: HostTaskResult)
pub fn insert_host_result<K>(&mut self, hostname: K, result: HostTaskResult)
Inserts or updates the execution result for a specific host.
If a result already exists for the given hostname, it will be replaced with the new result.
§Parameters
hostname- The hostname to associate with the result. Can be any type that implementsInto<NatString>, such as&str,String, orNatString.result- TheHostTaskResultcontaining the execution outcome for this host.
Sourcepub fn host_result(&self, hostname: &str) -> Option<&HostTaskResult>
pub fn host_result(&self, hostname: &str) -> Option<&HostTaskResult>
Sourcepub fn host_result_mut(&mut self, hostname: &str) -> Option<&mut HostTaskResult>
pub fn host_result_mut(&mut self, hostname: &str) -> Option<&mut HostTaskResult>
Sourcepub fn hosts(&self) -> &CustomTreeMap<HostTaskResult>
pub fn hosts(&self) -> &CustomTreeMap<HostTaskResult>
Returns a reference to the map of all host results.
§Returns
A reference to the CustomTreeMap containing hostname to HostTaskResult mappings.
Sourcepub fn insert_sub_task<K>(&mut self, task_name: K, results: TaskResults)
pub fn insert_sub_task<K>(&mut self, task_name: K, results: TaskResults)
Inserts or updates the results for a sub-task.
If results already exist for the given sub-task name, they will be replaced with the new results.
§Parameters
task_name- The name of the sub-task. Can be any type that implementsInto<NatString>, such as&str,String, orNatString.results- TheTaskResultscontaining the execution results for this sub-task.
Sourcepub fn sub_task(&self, task_name: &str) -> Option<&TaskResults>
pub fn sub_task(&self, task_name: &str) -> Option<&TaskResults>
Sourcepub fn sub_task_mut(&mut self, task_name: &str) -> Option<&mut TaskResults>
pub fn sub_task_mut(&mut self, task_name: &str) -> Option<&mut TaskResults>
Sourcepub fn sub_tasks(&self) -> &CustomTreeMap<TaskResults>
pub fn sub_tasks(&self) -> &CustomTreeMap<TaskResults>
Returns a reference to the map of all sub-task results.
§Returns
A reference to the CustomTreeMap containing sub-task name to TaskResults mappings.
Sourcepub fn passed_hosts(&self) -> Vec<&NatString>
pub fn passed_hosts(&self) -> Vec<&NatString>
Returns a list of hostnames for which the task execution passed.
This method filters the host results and collects the hostnames where the
HostTaskResult indicates a successful execution (passed state).
§Returns
A Vec containing references to the hostnames of all hosts where the task passed.
Sourcepub fn failed_hosts(&self) -> Vec<&NatString>
pub fn failed_hosts(&self) -> Vec<&NatString>
Returns a list of hostnames for which the task execution failed.
This method filters the host results and collects the hostnames where the
HostTaskResult indicates a failed execution.
§Returns
A Vec containing references to the hostnames of all hosts where the task failed.
Sourcepub fn skipped_hosts(&self) -> Vec<&NatString>
pub fn skipped_hosts(&self) -> Vec<&NatString>
Returns a list of hostnames for which the task execution was skipped.
Sourcepub fn host_summary(&self) -> TaskHostSummary
pub fn host_summary(&self) -> TaskHostSummary
Returns aggregate host counts for this task only.
Sourcepub fn task_summary(&self) -> TaskResultsSummary
pub fn task_summary(&self) -> TaskResultsSummary
Returns a recursive summary of this task and all sub-tasks.
Trait Implementations§
Source§impl Clone for TaskResults
impl Clone for TaskResults
Source§fn clone(&self) -> TaskResults
fn clone(&self) -> TaskResults
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more