Update Architecture
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
The bot follows a modular, async-first architecture designed for reliability, performance, and maintainability.
|
The bot follows a modular, async-first architecture designed for reliability, performance, and maintainability.
|
||||||
|
|
||||||
### System Architecture
|
## System Architecture
|
||||||
|
|
||||||
```
|
```
|
||||||
┌─────────────────────────────────────────────────────────────┐
|
┌─────────────────────────────────────────────────────────────┐
|
||||||
@@ -45,9 +45,9 @@ The bot follows a modular, async-first architecture designed for reliability, pe
|
|||||||
└─────────────────────────────────────────────────────────────┘
|
└─────────────────────────────────────────────────────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
### Core Components
|
## Core Components
|
||||||
|
|
||||||
#### 1. **PterodactylBot** (`pterodisbot.py`)
|
### 1. **PterodactylBot** (`pterodisbot.py`)
|
||||||
Main orchestrator class that coordinates all bot operations.
|
Main orchestrator class that coordinates all bot operations.
|
||||||
|
|
||||||
**Responsibilities:**
|
**Responsibilities:**
|
||||||
@@ -70,7 +70,7 @@ Main orchestrator class that coordinates all bot operations.
|
|||||||
- **Strategy Pattern**: Different update strategies based on state changes
|
- **Strategy Pattern**: Different update strategies based on state changes
|
||||||
- **Factory Pattern**: Creates embeds and views dynamically
|
- **Factory Pattern**: Creates embeds and views dynamically
|
||||||
|
|
||||||
#### 2. **PterodactylAPI** (`pterodisbot.py`)
|
### 2. **PterodactylAPI** (`pterodisbot.py`)
|
||||||
Abstraction layer for all Pterodactyl Panel API interactions.
|
Abstraction layer for all Pterodactyl Panel API interactions.
|
||||||
|
|
||||||
**Responsibilities:**
|
**Responsibilities:**
|
||||||
@@ -90,7 +90,7 @@ Abstraction layer for all Pterodactyl Panel API interactions.
|
|||||||
- Automatic retry with exponential backoff
|
- Automatic retry with exponential backoff
|
||||||
- Comprehensive error response handling
|
- Comprehensive error response handling
|
||||||
|
|
||||||
#### 3. **ServerMetricsGraphs** (`server_metrics_graphs.py`)
|
### 3. **ServerMetricsGraphs** (`server_metrics_graphs.py`)
|
||||||
Time-series data tracking and visualization for individual servers.
|
Time-series data tracking and visualization for individual servers.
|
||||||
|
|
||||||
**Responsibilities:**
|
**Responsibilities:**
|
||||||
@@ -116,7 +116,7 @@ deque([
|
|||||||
], maxlen=6)
|
], maxlen=6)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 4. **ServerMetricsManager** (`server_metrics_graphs.py`)
|
### 4. **ServerMetricsManager** (`server_metrics_graphs.py`)
|
||||||
Global coordinator for all server metrics tracking.
|
Global coordinator for all server metrics tracking.
|
||||||
|
|
||||||
**Responsibilities:**
|
**Responsibilities:**
|
||||||
@@ -131,7 +131,7 @@ Global coordinator for all server metrics tracking.
|
|||||||
- Summary statistics generation
|
- Summary statistics generation
|
||||||
- Thread-safe operations
|
- Thread-safe operations
|
||||||
|
|
||||||
#### 5. **ServerStatusView** (`pterodisbot.py`)
|
### 5. **ServerStatusView** (`pterodisbot.py`)
|
||||||
Discord UI component providing interactive server controls.
|
Discord UI component providing interactive server controls.
|
||||||
|
|
||||||
**Responsibilities:**
|
**Responsibilities:**
|
||||||
@@ -152,9 +152,9 @@ Discord UI component providing interactive server controls.
|
|||||||
- Interaction-level authorization checks
|
- Interaction-level authorization checks
|
||||||
- Ephemeral responses for sensitive data
|
- Ephemeral responses for sensitive data
|
||||||
|
|
||||||
### Data Flow
|
## Data Flow
|
||||||
|
|
||||||
#### Server Status Update Flow
|
### Server Status Update Flow
|
||||||
|
|
||||||
```
|
```
|
||||||
1. Background Task (every 10s)
|
1. Background Task (every 10s)
|
||||||
@@ -184,7 +184,7 @@ Discord UI component providing interactive server controls.
|
|||||||
└─> Determine if update needed
|
└─> Determine if update needed
|
||||||
```
|
```
|
||||||
|
|
||||||
#### User Interaction Flow
|
### User Interaction Flow
|
||||||
|
|
||||||
```
|
```
|
||||||
1. User Types /server_status
|
1. User Types /server_status
|
||||||
@@ -211,7 +211,7 @@ Discord UI component providing interactive server controls.
|
|||||||
└─> Send ephemeral response
|
└─> Send ephemeral response
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configuration System
|
## Configuration System
|
||||||
|
|
||||||
The bot uses a multi-layer configuration system:
|
The bot uses a multi-layer configuration system:
|
||||||
|
|
||||||
@@ -232,9 +232,9 @@ The bot uses a multi-layer configuration system:
|
|||||||
- URL format (includes protocol)
|
- URL format (includes protocol)
|
||||||
- Raises `ConfigValidationError` on failure
|
- Raises `ConfigValidationError` on failure
|
||||||
|
|
||||||
### Persistent Storage
|
## Persistent Storage
|
||||||
|
|
||||||
#### Embed Locations (`embed/embed_locations.json`)
|
### Embed Locations (`embed/embed_locations.json`)
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"server_abc123": {
|
"server_abc123": {
|
||||||
@@ -249,7 +249,7 @@ The bot uses a multi-layer configuration system:
|
|||||||
- **Save**: After each embed create/delete
|
- **Save**: After each embed create/delete
|
||||||
- **Cleanup**: Automatic on missing messages
|
- **Cleanup**: Automatic on missing messages
|
||||||
|
|
||||||
#### Server State Tracking (in-memory)
|
### Server State Tracking (in-memory)
|
||||||
```python
|
```python
|
||||||
{
|
{
|
||||||
"server_abc123": (
|
"server_abc123": (
|
||||||
@@ -265,7 +265,7 @@ The bot uses a multi-layer configuration system:
|
|||||||
- Reduces unnecessary Discord API calls
|
- Reduces unnecessary Discord API calls
|
||||||
- Tracks force update intervals
|
- Tracks force update intervals
|
||||||
|
|
||||||
### Async Architecture
|
## Async Architecture
|
||||||
|
|
||||||
The bot is built on asyncio for concurrent operations:
|
The bot is built on asyncio for concurrent operations:
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ async with asyncio.gather(*[
|
|||||||
- `asyncio.Lock()` for embed update cycles
|
- `asyncio.Lock()` for embed update cycles
|
||||||
- No blocking operations in event loop
|
- No blocking operations in event loop
|
||||||
|
|
||||||
### Error Handling Strategy
|
## Error Handling Strategy
|
||||||
|
|
||||||
**Levels:**
|
**Levels:**
|
||||||
1. **Graceful Degradation**: Continue operating with reduced functionality
|
1. **Graceful Degradation**: Continue operating with reduced functionality
|
||||||
@@ -309,9 +309,9 @@ except Exception as e:
|
|||||||
return {'attributes': {'current_state': 'offline'}}
|
return {'attributes': {'current_state': 'offline'}}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Performance Optimizations
|
## Performance Optimizations
|
||||||
|
|
||||||
#### 1. Smart Update Logic
|
### 1. Smart Update Logic
|
||||||
Only updates embeds when necessary:
|
Only updates embeds when necessary:
|
||||||
- Power state changes (always)
|
- Power state changes (always)
|
||||||
- Significant CPU changes (>50% delta)
|
- Significant CPU changes (>50% delta)
|
||||||
@@ -320,13 +320,13 @@ Only updates embeds when necessary:
|
|||||||
|
|
||||||
**Impact**: ~90% reduction in Discord API calls
|
**Impact**: ~90% reduction in Discord API calls
|
||||||
|
|
||||||
#### 2. FIFO Metric Queues
|
### 2. FIFO Metric Queues
|
||||||
`collections.deque(maxlen=6)` automatically rotates old data:
|
`collections.deque(maxlen=6)` automatically rotates old data:
|
||||||
- O(1) append operations
|
- O(1) append operations
|
||||||
- Automatic memory management
|
- Automatic memory management
|
||||||
- No manual cleanup needed
|
- No manual cleanup needed
|
||||||
|
|
||||||
#### 3. Request Locking
|
### 3. Request Locking
|
||||||
Prevents concurrent API access:
|
Prevents concurrent API access:
|
||||||
```python
|
```python
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
@@ -339,7 +339,7 @@ async with self.lock:
|
|||||||
- Prevents race conditions
|
- Prevents race conditions
|
||||||
- Ensures ordered operations
|
- Ensures ordered operations
|
||||||
|
|
||||||
#### 4. Caching Strategy
|
### 4. Caching Strategy
|
||||||
- Server list cached between updates
|
- Server list cached between updates
|
||||||
- State tracking prevents redundant checks
|
- State tracking prevents redundant checks
|
||||||
- Embed locations loaded once at startup
|
- Embed locations loaded once at startup
|
||||||
Reference in New Issue
Block a user