Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

brokkr-models::models::agent_events Rust

Structs

brokkr-models::models::agent_events::AgentEvent

pub

Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema, ``

Represents an agent event in the database.

Fields

NameTypeDescription
idUuidUnique identifier for the event.
created_atDateTime < Utc >Timestamp when the event was created.
updated_atDateTime < Utc >Timestamp when the event was last updated.
deleted_atOption < DateTime < Utc > >Timestamp for soft deletion, if applicable.
agent_idUuidID of the agent associated with this event.
deployment_object_idUuidID of the deployment object associated with this event.
event_typeStringType of the event.
statusStringStatus of the event (e.g., “SUCCESS”, “FAILURE”, “IN_PROGRESS”, “PENDING”).
messageOption < String >Optional message providing additional details about the event.

brokkr-models::models::agent_events::NewAgentEvent

pub

Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema

Represents a new agent event to be inserted into the database.

Fields

NameTypeDescription
agent_idUuidID of the agent associated with this event.
deployment_object_idUuidID of the deployment object associated with this event.
event_typeStringType of the event.
statusStringStatus of the event (e.g., “SUCCESS”, “FAILURE”).
messageOption < String >Optional message providing additional details about the event.

Methods

new pub
#![allow(unused)]
fn main() {
fn new (agent_id : Uuid , deployment_object_id : Uuid , event_type : String , status : String , message : Option < String > ,) -> Result < Self , String >
}

Creates a new NewAgentEvent instance.

Parameters:

NameTypeDescription
agent_id-UUID of the agent associated with this event.
deployment_object_id-UUID of the deployment object associated with this event.
event_type-Type of the event. Must be a non-empty string.
status-Status of the event. Must be one of: “SUCCESS”, “FAILURE”.
message-Optional message providing additional details about the event.

Returns:

Returns Ok(NewAgentEvent) if all parameters are valid, otherwise returns an Err with a description of the validation failure.

Source
#![allow(unused)]
fn main() {
    pub fn new(
        agent_id: Uuid,
        deployment_object_id: Uuid,
        event_type: String,
        status: String,
        message: Option<String>,
    ) -> Result<Self, String> {
        // Validate agent_id
        if agent_id.is_nil() {
            return Err("Invalid agent ID".to_string());
        }

        // Validate deployment_object_id
        if deployment_object_id.is_nil() {
            return Err("Invalid deployment object ID".to_string());
        }

        // Validate event_type
        if event_type.trim().is_empty() {
            return Err("Event type cannot be empty".to_string());
        }

        // Validate status
        let valid_statuses = ["SUCCESS", "FAILURE"];
        if !valid_statuses.contains(&status.as_str()) {
            return Err(format!(
                "Invalid status. Must be one of: {}",
                valid_statuses.join(", ")
            ));
        }

        Ok(NewAgentEvent {
            agent_id,
            deployment_object_id,
            event_type,
            status,
            message,
        })
    }
}