Skip to main content

TaskSuccess

Struct TaskSuccess 

Source
pub struct TaskSuccess { /* private fields */ }
Expand description

Represents the successful execution of a task on a host.

TaskSuccess captures detailed information about a task that completed successfully, including the execution result, whether changes were made, timing information, and any warnings or messages generated during execution. This structure provides a comprehensive view of what happened during task execution, even when the task succeeded.

§Fields

  • result - The structured result data produced by the task, if any. This can contain arbitrary JSON data representing the task’s output.

  • changed - Indicates whether the task made any changes to the target system. This is important for idempotency tracking and reporting.

  • diff - A textual representation of changes made, useful for showing what was modified before and after the task execution.

  • summary - A human-readable summary message describing what the task accomplished.

  • warnings - A list of warning messages generated during execution. Warnings indicate potential issues that didn’t prevent success but may require attention.

  • messages - Structured messages with levels (Info, Warning, Error, Debug) that provide detailed execution information beyond simple warnings.

  • metadata - Additional structured metadata about the execution, such as version information, configuration details, or other contextual data.

  • 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.

§Example

use genja_core::task::TaskSuccess;
use serde_json::json;

let success = TaskSuccess::new()
    .with_result(json!({"status": "deployed"}))
    .with_changed(true)
    .with_summary("Configuration deployed successfully")
    .with_warning("Using deprecated configuration format")
    .with_diff("- old_value\n+ new_value");

assert!(success.changed());
assert_eq!(success.warnings().len(), 1);

Implementations§

Source§

impl TaskSuccess

Source

pub fn new() -> Self

Creates a new TaskSuccess instance with default values.

This constructor initializes a TaskSuccess with all fields set to their default values: no result data, no changes made, no diff, no summary, empty warnings and messages lists, no metadata, and no timing information.

§Returns

A new TaskSuccess instance with default values for all fields.

Source

pub fn with_result(self, result: Value) -> Self

Sets the structured result data produced by the task.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining. The result can contain arbitrary JSON data representing the task’s output, such as configuration details, status information, or any other structured data relevant to the task execution.

§Parameters
  • result - A serde_json::Value containing the structured result data.
§Returns

The modified TaskSuccess instance with the result data set.

Source

pub fn with_changed(self, changed: bool) -> Self

Sets whether the task made changes to the target system.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining. The changed flag is important for idempotency tracking and reporting, indicating whether the task modified the system state or found it already in the desired state.

§Parameters
  • changed - true if the task made changes to the system, false if no changes were necessary or made.
§Returns

The modified TaskSuccess instance with the changed flag set.

Source

pub fn with_diff(self, diff: impl Into<String>) -> Self

Sets a textual representation of changes made by the task.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining. The diff typically shows what was modified, often in a before/after format, making it easy to understand what changed during execution.

§Parameters
  • diff - A textual representation of the changes. Can be any type that implements Into<String>, such as &str, String, or other string-like types.
§Returns

The modified TaskSuccess instance with the diff set.

Source

pub fn with_summary(self, summary: impl Into<String>) -> Self

Sets a human-readable summary message describing what the task accomplished.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining. The summary provides a concise description of the task’s outcome, useful for logging and reporting.

§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 TaskSuccess instance with the summary set.

Source

pub fn with_warning(self, warning: impl Into<String>) -> Self

Adds a warning message to the list of warnings generated during execution.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining. Warnings indicate potential issues that didn’t prevent success but may require attention. Multiple warnings can be added by calling this method multiple times.

§Parameters
  • warning - A warning message. Can be any type that implements Into<String>, such as &str, String, or other string-like types.
§Returns

The modified TaskSuccess instance with the warning added to the warnings list.

Source

pub fn with_message(self, message: TaskMessage) -> Self

Adds a structured message to the list of messages generated during execution.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining. Messages provide detailed execution information with associated severity levels. Multiple messages can be added by calling this method multiple times.

§Parameters
  • message - A TaskMessage containing the message text, severity level, and optional code and timestamp.
§Returns

The modified TaskSuccess instance with the message added to the messages list.

Source

pub fn with_metadata(self, metadata: Value) -> Self

Sets additional structured metadata about the execution.

This is a builder method that consumes self and returns the modified instance, allowing for method chaining. Metadata can contain arbitrary JSON data such as version information, configuration details, or other contextual data relevant to the task execution.

§Parameters
  • metadata - A serde_json::Value containing the structured metadata.
§Returns

The modified TaskSuccess instance with the metadata set.

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 TaskSuccess 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 TaskSuccess 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 TaskSuccess 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 result(&self) -> Option<&Value>

Returns the structured result data produced by the task, if available.

§Returns

Some(&Value) if result data was set, None otherwise.

Source

pub fn changed(&self) -> bool

Returns whether the task made changes to the target system.

§Returns

true if the task made changes, false if no changes were made.

Source

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

Returns the textual representation of changes made, if available.

§Returns

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

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 warnings(&self) -> &[String]

Returns a slice of all warning messages generated during execution.

§Returns

A slice containing all warning messages. Returns an empty slice if no warnings were generated.

Source

pub fn messages(&self) -> &[TaskMessage]

Returns a slice of all structured messages generated during execution.

§Returns

A slice containing all TaskMessage instances. Returns an empty slice if no messages were generated.

Source

pub fn metadata(&self) -> Option<&Value>

Returns the additional structured metadata, if available.

§Returns

Some(&Value) if metadata was set, None otherwise.

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.

Trait Implementations§

Source§

impl Clone for TaskSuccess

Source§

fn clone(&self) -> TaskSuccess

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 TaskSuccess

Source§

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

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

impl Default for TaskSuccess

Source§

fn default() -> TaskSuccess

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

impl Serialize for TaskSuccess

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.