Skip to main content

RegentTask

Struct RegentTask 

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

A unit of work for distributed configuration management.

A RegentTask is a self-contained task that can be serialized and sent across a network to be processed by a worker node. It contains all the information needed to connect to a host, assess or remediate its compliance with an expected state, and return the results.

Each task has a unique idempotency key that enables task-level idempotency. If the same task is delivered multiple times (e.g., due to message queue redelivery), external systems can use this key to deduplicate the task execution. This is separate from attribute-level idempotency, which is inherent to each attribute’s design.

§Serialization

Tasks implement Serialize and Deserialize, allowing them to be transmitted as JSON or YAML:

use regent_sdk::task::RegentTask;

let task = /* create task */;
let json = serde_json::to_string(&task).unwrap();
let yaml = serde_yaml::to_string(&task).unwrap();

§Example

use regent_sdk::task::{RegentTask, Job};
use regent_sdk::hosts::managed_host::ManagedHostBuilder;
use regent_sdk::state::ExpectedState;
use regent_sdk::hosts::handlers::{ConnectionMethod, TargetUser};

let host_builder = ManagedHostBuilder::new(
    "server-01",
    "192.168.1.100:22",
    Some(ConnectionMethod::Localhost(TargetUser::current_user())),
);

let expected_state = ExpectedState::new();
let task = RegentTask::from(host_builder, expected_state, Job::Assess);

println!("Task idempotency key: {}", task.idempotency_key());

Implementations§

Source§

impl RegentTask

Source

pub fn from( managed_host_builder: ManagedHostBuilder, expected_state: ExpectedState, job: Job, ) -> Self

Create a new RegentTask from a host builder, expected state, and job type.

§Arguments
  • managed_host_builder - Builder for the target host
  • expected_state - The expected state to assess/remedy
  • job - The type of job to perform (Assess or Reach)
§Returns

A new RegentTask with a randomly generated idempotency key for task-level idempotency. This allows external systems to detect and skip duplicate task deliveries.

§Example
use regent_sdk::task::{RegentTask, Job};
use regent_sdk::hosts::managed_host::ManagedHostBuilder;
use regent_sdk::state::ExpectedState;
use regent_sdk::hosts::handlers::{ConnectionMethod, TargetUser};

let host_builder = ManagedHostBuilder::new(
    "my-host",
    "localhost",
    Some(ConnectionMethod::Localhost(TargetUser::current_user())),
);

let expected_state = ExpectedState::new();
let task = RegentTask::from(host_builder, expected_state, Job::Assess);
Source

pub fn idempotency_key(&self) -> &str

Get the task-level idempotency key for this task.

This key is a unique identifier that enables task-level idempotency. When the same task is delivered multiple times to a worker, external systems can use this key to deduplicate the execution. Note: this is separate from attribute-level idempotency, which ensures each configuration change is safely repeatable.

§Returns

A reference to the idempotency key string.

§Example
use regent_sdk::task::RegentTask;

let task = /* create task */;
println!("Idempotency key: {}", task.idempotency_key());
Source

pub async fn run( &mut self, optional_secret_provider: Option<SecretProvidersPool>, ) -> Result<RegentTaskResult, RegentError>

Execute the task.

This method builds the managed host, connects to it, and performs the specified job (assess or reach compliance).

§Arguments
  • optional_secret_provider - Optional secret providers pool for retrieving secrets
§Returns

A RegentTaskResult containing the idempotency key and host status, or a RegentError if execution failed.

§Example
use regent_sdk::task::RegentTask;
use regent_sdk::secrets::{SecretProvider, SecretProvidersPoolBuilder};

let mut task = /* create task */;
let secrets_pool = SecretProvidersPoolBuilder::new()
    .add_default_provider("files", SecretProvider::files())
    .build()
    .unwrap();

let result = task.run(Some(secrets_pool)).await.unwrap();

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for RegentTask

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for RegentTask

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more