Skip to main content

TaskResults

Struct TaskResults 

Source
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 to HostTaskResult, containing the execution result for each host.
  • sub_tasks - A map of sub-task name to TaskResults, 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

Source

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 implements Into<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.

Source

pub fn task_name(&self) -> &str

Returns the name of the task.

§Returns

A string slice containing the task name.

Source

pub fn with_started_at(self, started_at: SystemTime) -> Self

Sets the task execution start timestamp.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining.

§Parameters
  • started_at - The timestamp when the task execution started.
§Returns

The modified TaskResults instance with the start timestamp set.

Source

pub fn with_finished_at(self, finished_at: SystemTime) -> Self

Sets the task execution finish timestamp.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining.

§Parameters
  • finished_at - The timestamp when the task execution finished.
§Returns

The modified TaskResults instance with the finish timestamp set.

Source

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.

Source

pub fn with_duration_ns(self, duration_ns: u128) -> Self

Sets the task execution duration in nanoseconds.

Source

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 implements Into<String>, such as &str, String, or other string-like types.
§Returns

The modified TaskResults instance with the summary set.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn duration_ns(&self) -> Option<u128>

Returns the task execution duration in nanoseconds, if available.

Source

pub fn started_at_display(&self) -> Option<String>

Returns the task execution start timestamp in RFC 3339 format, if available.

Source

pub fn finished_at_display(&self) -> Option<String>

Returns the task execution finish timestamp in RFC 3339 format, if available.

Source

pub fn duration_display(&self) -> Option<String>

Returns the task execution duration in a human-readable format, if available.

Source

pub fn to_json_string(&self) -> Result<String, Error>

Serializes task results as compact human-readable JSON.

Source

pub fn to_pretty_json_string(&self) -> Result<String, Error>

Serializes task results as pretty-printed human-readable JSON.

Source

pub fn to_raw_json_string(&self) -> Result<String, Error>

Serializes task results as compact raw JSON using the struct’s default serde representation.

Source

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.

Source

pub fn summary(&self) -> Option<&str>

Returns the task summary message, if available.

§Returns

Some(&str) if a summary was set, None otherwise.

Source

pub fn insert_host_result<K>(&mut self, hostname: K, result: HostTaskResult)
where K: Into<NatString>,

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 implements Into<NatString>, such as &str, String, or NatString.
  • result - The HostTaskResult containing the execution outcome for this host.
Source

pub fn host_result(&self, hostname: &str) -> Option<&HostTaskResult>

Retrieves the execution result for a specific host.

§Parameters
  • hostname - The hostname to look up.
§Returns

Some(&HostTaskResult) if a result exists for the hostname, None otherwise.

Source

pub fn host_result_mut(&mut self, hostname: &str) -> Option<&mut HostTaskResult>

Retrieves a mutable reference to the execution result for a specific host.

§Parameters
  • hostname - The hostname to look up.
§Returns

Some(&mut HostTaskResult) if a result exists for the hostname, None otherwise.

Source

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.

Source

pub fn insert_sub_task<K>(&mut self, task_name: K, results: TaskResults)
where K: Into<NatString>,

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 implements Into<NatString>, such as &str, String, or NatString.
  • results - The TaskResults containing the execution results for this sub-task.
Source

pub fn sub_task(&self, task_name: &str) -> Option<&TaskResults>

Retrieves the results for a specific sub-task.

§Parameters
  • task_name - The name of the sub-task to look up.
§Returns

Some(&TaskResults) if results exist for the sub-task, None otherwise.

Source

pub fn sub_task_mut(&mut self, task_name: &str) -> Option<&mut TaskResults>

Retrieves a mutable reference to the results for a specific sub-task.

§Parameters
  • task_name - The name of the sub-task to look up.
§Returns

Some(&mut TaskResults) if results exist for the sub-task, None otherwise.

Source

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.

Source

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.

Source

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.

Source

pub fn skipped_hosts(&self) -> Vec<&NatString>

Returns a list of hostnames for which the task execution was skipped.

Source

pub fn host_summary(&self) -> TaskHostSummary

Returns aggregate host counts for this task only.

Source

pub fn task_summary(&self) -> TaskResultsSummary

Returns a recursive summary of this task and all sub-tasks.

Trait Implementations§

Source§

impl Clone for TaskResults

Source§

fn clone(&self) -> TaskResults

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TaskResults

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TaskResults

Source§

fn default() -> TaskResults

Returns the “default value” for a type. Read more
Source§

impl Serialize for TaskResults

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.