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 keycreated_at: TIMESTAMP, when the event was createdupdated_at: TIMESTAMP, when the event was last updateddeleted_at: TIMESTAMP, for soft deletion supportagent_id: UUID, foreign key referencing theagentstabledeployment_object_id: UUID, foreign key referencing thedeployment_objectstableevent_type: VARCHAR(50), type of the eventstatus: VARCHAR(10), status of the eventmessage: 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_idanddeployment_object_idmust be valid, non-nil UUIDs. event_typemust be a non-empty string.statusmust be one of: “SUCCESS”, “FAILURE”, “IN_PROGRESS”, or “PENDING”.
Structs
Section titled “Structs”struct AgentEvent
Section titled “struct AgentEvent”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema
Represents an agent event in the database.
Fields
Section titled “Fields”| 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. |
struct NewAgentEvent
Section titled “struct NewAgentEvent”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema
Represents a new agent event to be inserted into the database.
Fields
Section titled “Fields”| 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. |
Methods
Section titled “Methods”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, }) }