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
impl TaskSuccess
Sourcepub fn new() -> Self
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.
Sourcepub fn with_result(self, result: Value) -> Self
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- Aserde_json::Valuecontaining the structured result data.
§Returns
The modified TaskSuccess instance with the result data set.
Sourcepub fn with_changed(self, changed: bool) -> Self
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-trueif the task made changes to the system,falseif no changes were necessary or made.
§Returns
The modified TaskSuccess instance with the changed flag set.
Sourcepub fn with_diff(self, diff: impl Into<String>) -> Self
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 implementsInto<String>, such as&str,String, or other string-like types.
§Returns
The modified TaskSuccess instance with the diff set.
Sourcepub fn with_summary(self, summary: impl Into<String>) -> Self
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 implementsInto<String>, such as&str,String, or other string-like types.
§Returns
The modified TaskSuccess instance with the summary set.
Sourcepub fn with_warning(self, warning: impl Into<String>) -> Self
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 implementsInto<String>, such as&str,String, or other string-like types.
§Returns
The modified TaskSuccess instance with the warning added to the warnings list.
Sourcepub fn with_message(self, message: TaskMessage) -> Self
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- ATaskMessagecontaining the message text, severity level, and optional code and timestamp.
§Returns
The modified TaskSuccess instance with the message added to the messages list.
Sourcepub fn with_metadata(self, metadata: Value) -> Self
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- Aserde_json::Valuecontaining the structured metadata.
§Returns
The modified TaskSuccess instance with the metadata set.
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 TaskSuccess 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 result(&self) -> Option<&Value>
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.
Sourcepub fn changed(&self) -> bool
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.
Sourcepub fn diff(&self) -> Option<&str>
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.
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 warnings(&self) -> &[String]
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.
Sourcepub fn messages(&self) -> &[TaskMessage]
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.
Sourcepub fn metadata(&self) -> Option<&Value>
pub fn metadata(&self) -> Option<&Value>
Returns the additional structured metadata, if available.
§Returns
Some(&Value) if metadata was set, None otherwise.
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.
Trait Implementations§
Source§impl Clone for TaskSuccess
impl Clone for TaskSuccess
Source§fn clone(&self) -> TaskSuccess
fn clone(&self) -> TaskSuccess
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more