Skip to content

brokkr-models::models::agent_events

Rust

Agent Event Module

This module defines structures and methods for managing agent events in the system.

Data Model

Agent events represent actions or occurrences related to agents and deployment objects. They are stored in the agent_events table with the following structure:

  • id: UUID, primary key
  • created_at: TIMESTAMP, when the event was created
  • updated_at: TIMESTAMP, when the event was last updated
  • deleted_at: TIMESTAMP, for soft deletion support
  • agent_id: UUID, foreign key referencing the agents table
  • deployment_object_id: UUID, foreign key referencing the deployment_objects table
  • event_type: VARCHAR(50), type of the event
  • status: VARCHAR(10), status of the event
  • message: TEXT, optional message associated with the event

Usage

Agent events are used to track and record various actions and statuses related to agents and their interactions with deployment objects. This can be useful for monitoring, debugging, and auditing purposes.

Constraints

  • Both agent_id and deployment_object_id must be valid, non-nil UUIDs.
  • event_type must be a non-empty string.
  • status must be one of: “SUCCESS”, “FAILURE”, “IN_PROGRESS”, or “PENDING”.

pub

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

Represents an agent event in the database.

Name Type Description
id Uuid Unique identifier for the event.
created_at DateTime<Utc> Timestamp when the event was created.
updated_at DateTime<Utc> Timestamp when the event was last updated.
deleted_at Option<DateTime<Utc>> Timestamp for soft deletion, if applicable.
agent_id Uuid ID of the agent associated with this event.
deployment_object_id Uuid ID of the deployment object associated with this event.
event_type String Type of the event.
status String Status of the event (e.g., “SUCCESS”, “FAILURE”, “IN_PROGRESS”, “PENDING”).
message Option<String> Optional message providing additional details about the event.

pub

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

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

Name Type Description
agent_id Uuid ID of the agent associated with this event.
deployment_object_id Uuid ID of the deployment object associated with this event.
event_type String Type of the event.
status String Status of the event (e.g., “SUCCESS”, “FAILURE”).
message Option<String> Optional message providing additional details about the event.

pub

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:

Name Type Description
agent_id Uuid UUID of the agent associated with this event.
deployment_object_id Uuid UUID of the deployment object associated with this event.
event_type String Type of the event. Must be a non-empty string.
status String Status of the event. Must be one of: “SUCCESS”, “FAILURE”.
message Option<String> 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
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,
})
}