Skip to content

brokkr-models::models::diagnostic_requests

Rust

Diagnostic Request model for on-demand diagnostic requests.

Diagnostic requests are created by operators to request detailed diagnostic information from agents about specific deployment objects.

pub

Derives: Debug, Clone, Queryable, Selectable, Identifiable, Serialize, Deserialize, ToSchema

A diagnostic request record from the database.

Name Type Description
id Uuid Unique identifier for the diagnostic request.
agent_id Uuid The agent that should handle this request.
deployment_object_id Uuid The deployment object to gather diagnostics for.
status String Status: pending, claimed, completed, failed, expired.
requested_by Option<String> Who requested the diagnostics (e.g., operator username).
created_at DateTime<Utc> When the request was created.
claimed_at Option<DateTime<Utc>> When the agent claimed the request.
completed_at Option<DateTime<Utc>> When the request was completed.
expires_at DateTime<Utc> When the request expires and should be cleaned up.

pub

Derives: Debug, Clone, Insertable, Serialize, Deserialize

A new diagnostic request to be inserted.

Name Type Description
agent_id Uuid The agent that should handle this request.
deployment_object_id Uuid The deployment object to gather diagnostics for.
status String Status (defaults to “pending”).
requested_by Option<String> Who requested the diagnostics.
expires_at DateTime<Utc> When the request expires.

pub

fn new(
agent_id: Uuid,
deployment_object_id: Uuid,
requested_by: Option<String>,
retention_minutes: Option<i64>,
) -> Result<Self, String>

Creates a new diagnostic request.

Parameters:

Name Type Description
agent_id Uuid The agent that should handle this request.
deployment_object_id Uuid The deployment object to gather diagnostics for.
requested_by Option<String> Optional identifier of who requested the diagnostics.
retention_minutes Option<i64> How long the request should be retained (default 60).

Returns:

A Result containing the new diagnostic request or an error.

Source
pub fn new(
agent_id: Uuid,
deployment_object_id: Uuid,
requested_by: Option<String>,
retention_minutes: Option<i64>,
) -> Result<Self, String> {
// Validate UUIDs are not nil
if agent_id.is_nil() {
return Err("Agent ID cannot be nil".to_string());
}
if deployment_object_id.is_nil() {
return Err("Deployment object ID cannot be nil".to_string());
}
let retention = retention_minutes.unwrap_or(60);
if !(1..=1440).contains(&retention) {
return Err("Retention must be between 1 and 1440 minutes".to_string());
}
let expires_at = Utc::now() + Duration::minutes(retention);
Ok(Self {
agent_id,
deployment_object_id,
status: "pending".to_string(),
requested_by,
expires_at,
})
}

pub

Derives: Debug, Clone, AsChangeset

Changeset for updating a diagnostic request.

Name Type Description
status Option<String> New status.
claimed_at Option<DateTime<Utc>> When claimed.
completed_at Option<DateTime<Utc>> When completed.
Name Type Value Description
VALID_STATUSES &[&str] &["pending", "claimed", "completed", "failed", "expired"] Valid diagnostic request statuses