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
impl RegentTask
Sourcepub fn from(
managed_host_builder: ManagedHostBuilder,
expected_state: ExpectedState,
job: Job,
) -> Self
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 hostexpected_state- The expected state to assess/remedyjob- The type of job to perform (AssessorReach)
§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);Sourcepub fn idempotency_key(&self) -> &str
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());Sourcepub async fn run(
&mut self,
optional_secret_provider: Option<SecretProvidersPool>,
) -> Result<RegentTaskResult, RegentError>
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();