rename worker to actor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Hero Supervisor CLI Example
|
||||
|
||||
This example demonstrates how to use the `hive-supervisor` CLI tool for managing workers and jobs in the Hero ecosystem.
|
||||
This example demonstrates how to use the `hive-supervisor` CLI tool for managing actors and jobs in the Hero ecosystem.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@@ -19,20 +19,20 @@ This example demonstrates how to use the `hive-supervisor` CLI tool for managing
|
||||
# Follow Zinit installation instructions for your platform
|
||||
```
|
||||
|
||||
3. **Worker Binaries**: The configuration references worker binaries that need to be available:
|
||||
- `/usr/local/bin/osis_worker`
|
||||
- `/usr/local/bin/sal_worker`
|
||||
- `/usr/local/bin/v_worker`
|
||||
- `/usr/local/bin/python_worker`
|
||||
3. **Actor Binaries**: The configuration references actor binaries that need to be available:
|
||||
- `/usr/local/bin/osis_actor`
|
||||
- `/usr/local/bin/sal_actor`
|
||||
- `/usr/local/bin/v_actor`
|
||||
- `/usr/local/bin/python_actor`
|
||||
|
||||
For testing purposes, you can create mock worker binaries or update the paths in `config.toml` to point to existing binaries.
|
||||
For testing purposes, you can create mock actor binaries or update the paths in `config.toml` to point to existing binaries.
|
||||
|
||||
## Configuration
|
||||
|
||||
The `config.toml` file contains the supervisor configuration:
|
||||
|
||||
- **Global settings**: Redis URL and Zinit socket path
|
||||
- **Worker configurations**: Binary paths and environment variables for each worker type
|
||||
- **Actor configurations**: Binary paths and environment variables for each actor type
|
||||
|
||||
## Usage Examples
|
||||
|
||||
@@ -43,29 +43,29 @@ The `config.toml` file contains the supervisor configuration:
|
||||
cargo build --bin hive-supervisor --release
|
||||
```
|
||||
|
||||
### 2. Worker Management
|
||||
### 2. Actor Management
|
||||
|
||||
```bash
|
||||
# Show help
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml --help
|
||||
|
||||
# List all configured workers
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml workers list
|
||||
# List all configured actors
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml actors list
|
||||
|
||||
# Start all workers
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml workers start
|
||||
# Start all actors
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml actors start
|
||||
|
||||
# Start specific workers
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml workers start osis_worker sal_worker
|
||||
# Start specific actors
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml actors start osis_actor sal_actor
|
||||
|
||||
# Check worker status
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml workers status
|
||||
# Check actor status
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml actors status
|
||||
|
||||
# Stop all workers
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml workers stop
|
||||
# Stop all actors
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml actors stop
|
||||
|
||||
# Restart specific worker
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml workers restart osis_worker
|
||||
# Restart specific actor
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml actors restart osis_actor
|
||||
```
|
||||
|
||||
### 3. Job Management
|
||||
@@ -73,7 +73,7 @@ cargo build --bin hive-supervisor --release
|
||||
```bash
|
||||
# Create a job with inline script
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml jobs create \
|
||||
--script 'print("Hello from OSIS worker!");' \
|
||||
--script 'print("Hello from OSIS actor!");' \
|
||||
--script-type osis \
|
||||
--caller-id "user123" \
|
||||
--context-id "session456"
|
||||
@@ -118,18 +118,18 @@ cargo build --bin hive-supervisor --release
|
||||
|
||||
```bash
|
||||
# Enable debug logging
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml -v workers status
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml -v actors status
|
||||
|
||||
# Enable trace logging
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml -vv workers status
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml -vv actors status
|
||||
|
||||
# Disable timestamps
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml --no-timestamp workers status
|
||||
./target/release/hive-supervisor --config examples/cli/config.toml --no-timestamp actors status
|
||||
```
|
||||
|
||||
## Sample Scripts
|
||||
|
||||
The `sample_scripts/` directory contains example scripts for different worker types:
|
||||
The `sample_scripts/` directory contains example scripts for different actor types:
|
||||
|
||||
- `hello_osis.rhai` - Simple OSIS/HeroScript example
|
||||
- `system_sal.rhai` - SAL system operation example
|
||||
@@ -148,9 +148,9 @@ The `sample_scripts/` directory contains example scripts for different worker ty
|
||||
- Verify Zinit is running and the socket path is correct
|
||||
- Check permissions on the socket file
|
||||
|
||||
3. **Worker Binary Not Found**
|
||||
3. **Actor Binary Not Found**
|
||||
- Update binary paths in `config.toml` to match your system
|
||||
- Ensure worker binaries are executable
|
||||
- Ensure actor binaries are executable
|
||||
|
||||
4. **Permission Denied**
|
||||
- Check file permissions on configuration and binary files
|
||||
@@ -161,7 +161,7 @@ The `sample_scripts/` directory contains example scripts for different worker ty
|
||||
Run with verbose logging to see detailed operation information:
|
||||
|
||||
```bash
|
||||
RUST_LOG=debug ./target/release/hive-supervisor --config examples/cli/config.toml -vv workers status
|
||||
RUST_LOG=debug ./target/release/hive-supervisor --config examples/cli/config.toml -vv actors status
|
||||
```
|
||||
|
||||
## Configuration Customization
|
||||
@@ -170,15 +170,15 @@ You can customize the configuration for your environment:
|
||||
|
||||
1. **Update Redis URL**: Change `redis_url` in the `[global]` section
|
||||
2. **Update Zinit Socket**: Change `zinit_socket_path` for your Zinit installation
|
||||
3. **Worker Paths**: Update binary paths in worker sections to match your setup
|
||||
4. **Environment Variables**: Add or modify environment variables for each worker type
|
||||
3. **Actor Paths**: Update binary paths in actor sections to match your setup
|
||||
4. **Environment Variables**: Add or modify environment variables for each actor type
|
||||
|
||||
## Integration with Hero Ecosystem
|
||||
|
||||
This CLI integrates with the broader Hero ecosystem:
|
||||
|
||||
- **Job Queue**: Uses Redis for job queuing and status tracking
|
||||
- **Process Management**: Uses Zinit for worker lifecycle management
|
||||
- **Process Management**: Uses Zinit for actor lifecycle management
|
||||
- **Script Execution**: Supports multiple script types (OSIS, SAL, V, Python)
|
||||
- **Monitoring**: Provides real-time status and logging capabilities
|
||||
|
||||
|
@@ -1,19 +1,19 @@
|
||||
# Hero Supervisor CLI Configuration Example
|
||||
# This configuration demonstrates how to set up the hive-supervisor CLI
|
||||
# with different worker types for script execution.
|
||||
# with different actor types for script execution.
|
||||
|
||||
[global]
|
||||
# Redis connection URL for job queuing
|
||||
redis_url = "redis://localhost:6379"
|
||||
|
||||
# OSIS Worker Configuration
|
||||
# OSIS Actor Configuration
|
||||
# Handles OSIS (HeroScript) execution
|
||||
[osis_worker]
|
||||
[osis_actor]
|
||||
binary_path = "../../../target/debug/osis"
|
||||
env_vars = { "RUST_LOG" = "info", "WORKER_TYPE" = "osis", "MAX_CONCURRENT_JOBS" = "5" }
|
||||
env_vars = { "RUST_LOG" = "info", "ACTOR_TYPE" = "osis", "MAX_CONCURRENT_JOBS" = "5" }
|
||||
|
||||
# SAL Worker Configuration
|
||||
# SAL Actor Configuration
|
||||
# Handles System Abstraction Layer scripts
|
||||
[sal_worker]
|
||||
[sal_actor]
|
||||
binary_path = "../../../target/debug/sal"
|
||||
env_vars = { "RUST_LOG" = "info", "WORKER_TYPE" = "sal", "MAX_CONCURRENT_JOBS" = "3" }
|
||||
env_vars = { "RUST_LOG" = "info", "ACTOR_TYPE" = "sal", "MAX_CONCURRENT_JOBS" = "3" }
|
@@ -58,25 +58,25 @@ fi
|
||||
echo -e "${BLUE}=== CLI Help and Information ===${NC}"
|
||||
run_cli "Show main help" --help
|
||||
|
||||
echo -e "${BLUE}=== Worker Management Examples ===${NC}"
|
||||
run_cli "List configured workers" workers list
|
||||
run_cli "Show worker management help" workers --help
|
||||
echo -e "${BLUE}=== Actor Management Examples ===${NC}"
|
||||
run_cli "List configured actors" actors list
|
||||
run_cli "Show actor management help" actors --help
|
||||
|
||||
# Note: These commands would require actual worker binaries and Zinit setup
|
||||
echo -e "${YELLOW}Note: The following commands require actual worker binaries and Zinit setup${NC}"
|
||||
# Note: These commands would require actual actor binaries and Zinit setup
|
||||
echo -e "${YELLOW}Note: The following commands require actual actor binaries and Zinit setup${NC}"
|
||||
echo -e "${YELLOW}They are shown for demonstration but may fail without proper setup${NC}"
|
||||
echo
|
||||
|
||||
# Uncomment these if you have the proper setup
|
||||
# run_cli "Check worker status" workers status
|
||||
# run_cli "Start all workers" workers start
|
||||
# run_cli "Check worker status after start" workers status
|
||||
# run_cli "Check actor status" actors status
|
||||
# run_cli "Start all actors" actors start
|
||||
# run_cli "Check actor status after start" actors status
|
||||
|
||||
echo -e "${BLUE}=== Job Management Examples ===${NC}"
|
||||
run_cli "Show job management help" jobs --help
|
||||
|
||||
# Create sample jobs (these will also require workers to be running)
|
||||
echo -e "${YELLOW}Sample job creation commands (require running workers):${NC}"
|
||||
# Create sample jobs (these will also require actors to be running)
|
||||
echo -e "${YELLOW}Sample job creation commands (require running actors):${NC}"
|
||||
echo
|
||||
|
||||
echo "# Create OSIS job with inline script:"
|
||||
@@ -123,22 +123,22 @@ echo
|
||||
|
||||
echo -e "${BLUE}=== Verbose Logging Examples ===${NC}"
|
||||
echo "# Debug logging:"
|
||||
echo "$CLI_BINARY --config $CONFIG_FILE -v workers list"
|
||||
echo "$CLI_BINARY --config $CONFIG_FILE -v actors list"
|
||||
echo
|
||||
echo "# Trace logging:"
|
||||
echo "$CLI_BINARY --config $CONFIG_FILE -vv workers list"
|
||||
echo "$CLI_BINARY --config $CONFIG_FILE -vv actors list"
|
||||
echo
|
||||
echo "# No timestamps:"
|
||||
echo "$CLI_BINARY --config $CONFIG_FILE --no-timestamp workers list"
|
||||
echo "$CLI_BINARY --config $CONFIG_FILE --no-timestamp actors list"
|
||||
echo
|
||||
|
||||
echo -e "${GREEN}=== Example Runner Complete ===${NC}"
|
||||
echo -e "${YELLOW}To run actual commands, ensure you have:${NC}"
|
||||
echo "1. Redis server running on localhost:6379"
|
||||
echo "2. Zinit process manager installed and configured"
|
||||
echo "3. Worker binaries available at the paths specified in config.toml"
|
||||
echo "3. Actor binaries available at the paths specified in config.toml"
|
||||
echo
|
||||
echo -e "${YELLOW}For testing without full setup, you can:${NC}"
|
||||
echo "1. Update config.toml with paths to existing binaries"
|
||||
echo "2. Use the CLI help commands and configuration validation"
|
||||
echo "3. Test the REPL mode (requires workers to be running)"
|
||||
echo "3. Test the REPL mode (requires actors to be running)"
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Sample Python script for demonstration
|
||||
This script demonstrates Python worker functionality
|
||||
This script demonstrates Python actor functionality
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -9,7 +9,7 @@ import datetime
|
||||
from typing import List, Dict
|
||||
|
||||
def main():
|
||||
print("=== Python Worker Demo ===")
|
||||
print("=== Python Actor Demo ===")
|
||||
print("Python data processing operations")
|
||||
|
||||
# Data structures
|
||||
|
@@ -1,8 +1,8 @@
|
||||
// Sample OSIS/HeroScript for demonstration
|
||||
// This script demonstrates basic OSIS worker functionality
|
||||
// This script demonstrates basic OSIS actor functionality
|
||||
|
||||
print("=== OSIS Worker Demo ===");
|
||||
print("Hello from the OSIS worker!");
|
||||
print("=== OSIS Actor Demo ===");
|
||||
print("Hello from the OSIS actor!");
|
||||
|
||||
// Basic variable operations
|
||||
let name = "Hero";
|
||||
|
@@ -1,12 +1,12 @@
|
||||
// Sample V language script for demonstration
|
||||
// This script demonstrates V worker functionality
|
||||
// This script demonstrates V actor functionality
|
||||
|
||||
module main
|
||||
|
||||
import math
|
||||
|
||||
fn main() {
|
||||
println("=== V Worker Demo ===")
|
||||
println("=== V Actor Demo ===")
|
||||
println("V language mathematical operations")
|
||||
|
||||
// Basic arithmetic
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// Sample SAL (System Abstraction Layer) script for demonstration
|
||||
// This script demonstrates system-level operations through SAL worker
|
||||
// This script demonstrates system-level operations through SAL actor
|
||||
|
||||
print("=== SAL Worker Demo ===");
|
||||
print("=== SAL Actor Demo ===");
|
||||
print("System Abstraction Layer operations");
|
||||
|
||||
// System information gathering
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use hero_supervisor::{
|
||||
Supervisor, SupervisorBuilder, WorkerConfig, WorkerLifecycleManager,
|
||||
WorkerLifecycleManagerBuilder, ScriptType
|
||||
Supervisor, SupervisorBuilder, ActorConfig, ActorLifecycleManager,
|
||||
ActorLifecycleManagerBuilder, ScriptType
|
||||
};
|
||||
use log::{info, warn, error};
|
||||
use std::collections::HashMap;
|
||||
@@ -13,7 +13,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Initialize logging
|
||||
env_logger::init();
|
||||
|
||||
info!("Starting Worker Lifecycle Management Demo");
|
||||
info!("Starting Actor Lifecycle Management Demo");
|
||||
|
||||
// Configuration
|
||||
let redis_url = "redis://localhost:6379";
|
||||
@@ -25,154 +25,154 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.context_id("demo_context")
|
||||
.build()?;
|
||||
|
||||
// Configure workers for different script types
|
||||
let mut worker_configs = Vec::new();
|
||||
// Configure actors for different script types
|
||||
let mut actor_configs = Vec::new();
|
||||
|
||||
// OSIS workers (Rhai/HeroScript)
|
||||
// OSIS actors (Rhai/HeroScript)
|
||||
for i in 0..2 {
|
||||
let config = WorkerConfig::new(
|
||||
format!("osis_worker_{}", i),
|
||||
PathBuf::from("/usr/local/bin/osis_worker"),
|
||||
let config = ActorConfig::new(
|
||||
format!("osis_actor_{}", i),
|
||||
PathBuf::from("/usr/local/bin/osis_actor"),
|
||||
ScriptType::OSIS,
|
||||
)
|
||||
.with_args(vec![
|
||||
"--redis-url".to_string(),
|
||||
redis_url.to_string(),
|
||||
"--worker-id".to_string(),
|
||||
format!("osis_worker_{}", i),
|
||||
"--actor-id".to_string(),
|
||||
format!("osis_actor_{}", i),
|
||||
])
|
||||
.with_env({
|
||||
let mut env = HashMap::new();
|
||||
env.insert("RUST_LOG".to_string(), "info".to_string());
|
||||
env.insert("WORKER_TYPE".to_string(), "osis".to_string());
|
||||
env.insert("ACTOR_TYPE".to_string(), "osis".to_string());
|
||||
env
|
||||
})
|
||||
.with_health_check("/usr/local/bin/osis_worker --health-check".to_string())
|
||||
.with_health_check("/usr/local/bin/osis_actor --health-check".to_string())
|
||||
.with_dependencies(vec!["redis".to_string()]);
|
||||
|
||||
worker_configs.push(config);
|
||||
actor_configs.push(config);
|
||||
}
|
||||
|
||||
// SAL workers (System Abstraction Layer)
|
||||
// SAL actors (System Abstraction Layer)
|
||||
for i in 0..3 {
|
||||
let config = WorkerConfig::new(
|
||||
format!("sal_worker_{}", i),
|
||||
PathBuf::from("/usr/local/bin/sal_worker"),
|
||||
let config = ActorConfig::new(
|
||||
format!("sal_actor_{}", i),
|
||||
PathBuf::from("/usr/local/bin/sal_actor"),
|
||||
ScriptType::SAL,
|
||||
)
|
||||
.with_args(vec![
|
||||
"--redis-url".to_string(),
|
||||
redis_url.to_string(),
|
||||
"--worker-id".to_string(),
|
||||
format!("sal_worker_{}", i),
|
||||
"--actor-id".to_string(),
|
||||
format!("sal_actor_{}", i),
|
||||
])
|
||||
.with_env({
|
||||
let mut env = HashMap::new();
|
||||
env.insert("RUST_LOG".to_string(), "info".to_string());
|
||||
env.insert("WORKER_TYPE".to_string(), "sal".to_string());
|
||||
env.insert("ACTOR_TYPE".to_string(), "sal".to_string());
|
||||
env
|
||||
})
|
||||
.with_health_check("/usr/local/bin/sal_worker --health-check".to_string())
|
||||
.with_health_check("/usr/local/bin/sal_actor --health-check".to_string())
|
||||
.with_dependencies(vec!["redis".to_string()]);
|
||||
|
||||
worker_configs.push(config);
|
||||
actor_configs.push(config);
|
||||
}
|
||||
|
||||
// V workers (HeroScript in V language)
|
||||
// V actors (HeroScript in V language)
|
||||
for i in 0..2 {
|
||||
let config = WorkerConfig::new(
|
||||
format!("v_worker_{}", i),
|
||||
PathBuf::from("/usr/local/bin/v_worker"),
|
||||
let config = ActorConfig::new(
|
||||
format!("v_actor_{}", i),
|
||||
PathBuf::from("/usr/local/bin/v_actor"),
|
||||
ScriptType::V,
|
||||
)
|
||||
.with_args(vec![
|
||||
"--redis-url".to_string(),
|
||||
redis_url.to_string(),
|
||||
"--worker-id".to_string(),
|
||||
format!("v_worker_{}", i),
|
||||
"--actor-id".to_string(),
|
||||
format!("v_actor_{}", i),
|
||||
])
|
||||
.with_env({
|
||||
let mut env = HashMap::new();
|
||||
env.insert("RUST_LOG".to_string(), "info".to_string());
|
||||
env.insert("WORKER_TYPE".to_string(), "v".to_string());
|
||||
env.insert("ACTOR_TYPE".to_string(), "v".to_string());
|
||||
env
|
||||
})
|
||||
.with_health_check("/usr/local/bin/v_worker --health-check".to_string())
|
||||
.with_health_check("/usr/local/bin/v_actor --health-check".to_string())
|
||||
.with_dependencies(vec!["redis".to_string()]);
|
||||
|
||||
worker_configs.push(config);
|
||||
actor_configs.push(config);
|
||||
}
|
||||
|
||||
// Create lifecycle manager
|
||||
let mut lifecycle_manager = WorkerLifecycleManagerBuilder::new(zinit_socket.to_string())
|
||||
let mut lifecycle_manager = ActorLifecycleManagerBuilder::new(zinit_socket.to_string())
|
||||
.with_supervisor(supervisor.clone());
|
||||
|
||||
// Add all worker configurations
|
||||
for config in worker_configs {
|
||||
lifecycle_manager = lifecycle_manager.add_worker(config);
|
||||
// Add all actor configurations
|
||||
for config in actor_configs {
|
||||
lifecycle_manager = lifecycle_manager.add_actor(config);
|
||||
}
|
||||
|
||||
let mut lifecycle_manager = lifecycle_manager.build();
|
||||
|
||||
// Demonstrate lifecycle operations
|
||||
info!("=== Starting Worker Lifecycle Demo ===");
|
||||
info!("=== Starting Actor Lifecycle Demo ===");
|
||||
|
||||
// 1. Start all workers
|
||||
info!("1. Starting all workers...");
|
||||
match lifecycle_manager.start_all_workers().await {
|
||||
Ok(_) => info!("✅ All workers started successfully"),
|
||||
// 1. Start all actors
|
||||
info!("1. Starting all actors...");
|
||||
match lifecycle_manager.start_all_actors().await {
|
||||
Ok(_) => info!("✅ All actors started successfully"),
|
||||
Err(e) => {
|
||||
error!("❌ Failed to start workers: {}", e);
|
||||
error!("❌ Failed to start actors: {}", e);
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for workers to initialize
|
||||
// Wait for actors to initialize
|
||||
sleep(Duration::from_secs(5)).await;
|
||||
|
||||
// 2. Check worker status
|
||||
info!("2. Checking worker status...");
|
||||
match lifecycle_manager.get_all_worker_status().await {
|
||||
// 2. Check actor status
|
||||
info!("2. Checking actor status...");
|
||||
match lifecycle_manager.get_all_actor_status().await {
|
||||
Ok(status_map) => {
|
||||
for (worker_name, status) in status_map {
|
||||
info!(" Worker '{}': State={:?}, PID={}", worker_name, status.state, status.pid);
|
||||
for (actor_name, status) in status_map {
|
||||
info!(" Actor '{}': State={:?}, PID={}", actor_name, status.state, status.pid);
|
||||
}
|
||||
}
|
||||
Err(e) => warn!("Failed to get worker status: {}", e),
|
||||
Err(e) => warn!("Failed to get actor status: {}", e),
|
||||
}
|
||||
|
||||
// 3. Demonstrate scaling
|
||||
info!("3. Demonstrating worker scaling...");
|
||||
info!("3. Demonstrating actor scaling...");
|
||||
|
||||
// Scale up OSIS workers
|
||||
info!(" Scaling up OSIS workers to 3...");
|
||||
if let Err(e) = lifecycle_manager.scale_workers(&ScriptType::OSIS, 3).await {
|
||||
warn!("Failed to scale OSIS workers: {}", e);
|
||||
// Scale up OSIS actors
|
||||
info!(" Scaling up OSIS actors to 3...");
|
||||
if let Err(e) = lifecycle_manager.scale_actors(&ScriptType::OSIS, 3).await {
|
||||
warn!("Failed to scale OSIS actors: {}", e);
|
||||
}
|
||||
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
|
||||
// Scale down SAL workers
|
||||
info!(" Scaling down SAL workers to 1...");
|
||||
if let Err(e) = lifecycle_manager.scale_workers(&ScriptType::SAL, 1).await {
|
||||
warn!("Failed to scale SAL workers: {}", e);
|
||||
// Scale down SAL actors
|
||||
info!(" Scaling down SAL actors to 1...");
|
||||
if let Err(e) = lifecycle_manager.scale_actors(&ScriptType::SAL, 1).await {
|
||||
warn!("Failed to scale SAL actors: {}", e);
|
||||
}
|
||||
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
|
||||
// 4. Check running worker counts
|
||||
info!("4. Checking running worker counts after scaling...");
|
||||
// 4. Check running actor counts
|
||||
info!("4. Checking running actor counts after scaling...");
|
||||
for script_type in [ScriptType::OSIS, ScriptType::SAL, ScriptType::V] {
|
||||
let count = lifecycle_manager.get_running_worker_count(&script_type).await;
|
||||
info!(" {:?}: {} workers running", script_type, count);
|
||||
let count = lifecycle_manager.get_running_actor_count(&script_type).await;
|
||||
info!(" {:?}: {} actors running", script_type, count);
|
||||
}
|
||||
|
||||
// 5. Demonstrate restart functionality
|
||||
info!("5. Demonstrating worker restart...");
|
||||
if let Err(e) = lifecycle_manager.restart_worker("osis_worker_0").await {
|
||||
warn!("Failed to restart worker: {}", e);
|
||||
info!("5. Demonstrating actor restart...");
|
||||
if let Err(e) = lifecycle_manager.restart_actor("osis_actor_0").await {
|
||||
warn!("Failed to restart actor: {}", e);
|
||||
} else {
|
||||
info!(" ✅ Successfully restarted osis_worker_0");
|
||||
info!(" ✅ Successfully restarted osis_actor_0");
|
||||
}
|
||||
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
@@ -180,12 +180,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 6. Simulate job dispatch and health monitoring
|
||||
info!("6. Simulating job dispatch and health monitoring...");
|
||||
|
||||
// Update job time for a worker (simulating job dispatch)
|
||||
lifecycle_manager.update_worker_job_time("sal_worker_0");
|
||||
info!(" Updated job time for sal_worker_0");
|
||||
// Update job time for a actor (simulating job dispatch)
|
||||
lifecycle_manager.update_actor_job_time("sal_actor_0");
|
||||
info!(" Updated job time for sal_actor_0");
|
||||
|
||||
// Perform health monitoring check
|
||||
if let Err(e) = lifecycle_manager.monitor_worker_health().await {
|
||||
if let Err(e) = lifecycle_manager.monitor_actor_health().await {
|
||||
warn!("Health monitoring failed: {}", e);
|
||||
} else {
|
||||
info!(" ✅ Health monitoring completed");
|
||||
@@ -196,7 +196,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let test_job = supervisor
|
||||
.new_job()
|
||||
.script_type(ScriptType::OSIS)
|
||||
.script_content("println!(\"Hello from worker!\");".to_string())
|
||||
.script_content("println!(\"Hello from actor!\");".to_string())
|
||||
.timeout(Duration::from_secs(30))
|
||||
.build()?;
|
||||
|
||||
@@ -208,27 +208,27 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 8. Demonstrate graceful shutdown
|
||||
info!("8. Demonstrating graceful shutdown...");
|
||||
|
||||
// Stop specific workers
|
||||
info!(" Stopping specific workers...");
|
||||
for worker_name in ["osis_worker_1", "v_worker_0"] {
|
||||
if let Err(e) = lifecycle_manager.stop_worker(worker_name).await {
|
||||
warn!("Failed to stop worker {}: {}", worker_name, e);
|
||||
// Stop specific actors
|
||||
info!(" Stopping specific actors...");
|
||||
for actor_name in ["osis_actor_1", "v_actor_0"] {
|
||||
if let Err(e) = lifecycle_manager.stop_actor(actor_name).await {
|
||||
warn!("Failed to stop actor {}: {}", actor_name, e);
|
||||
} else {
|
||||
info!(" ✅ Stopped worker: {}", worker_name);
|
||||
info!(" ✅ Stopped actor: {}", actor_name);
|
||||
}
|
||||
}
|
||||
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
|
||||
// Stop all remaining workers
|
||||
info!(" Stopping all remaining workers...");
|
||||
if let Err(e) = lifecycle_manager.stop_all_workers().await {
|
||||
error!("Failed to stop all workers: {}", e);
|
||||
// Stop all remaining actors
|
||||
info!(" Stopping all remaining actors...");
|
||||
if let Err(e) = lifecycle_manager.stop_all_actors().await {
|
||||
error!("Failed to stop all actors: {}", e);
|
||||
} else {
|
||||
info!(" ✅ All workers stopped successfully");
|
||||
info!(" ✅ All actors stopped successfully");
|
||||
}
|
||||
|
||||
info!("=== Worker Lifecycle Demo Completed ===");
|
||||
info!("=== Actor Lifecycle Demo Completed ===");
|
||||
|
||||
// Optional: Start health monitoring loop (commented out for demo)
|
||||
// info!("Starting health monitoring loop (Ctrl+C to stop)...");
|
||||
|
@@ -8,44 +8,44 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
info!("Starting Hero Supervisor Lifecycle Demo");
|
||||
|
||||
// Build supervisor with simplified worker configuration
|
||||
// Workers are automatically launched during build
|
||||
// Build supervisor with simplified actor configuration
|
||||
// Actors are automatically launched during build
|
||||
let supervisor = SupervisorBuilder::new()
|
||||
.redis_url("redis://localhost:6379")
|
||||
.osis_worker("/usr/local/bin/osis_worker")
|
||||
.sal_worker("/usr/local/bin/sal_worker")
|
||||
.v_worker("/usr/local/bin/v_worker")
|
||||
.worker_env_var("REDIS_URL", "redis://localhost:6379")
|
||||
.worker_env_var("LOG_LEVEL", "info")
|
||||
.osis_actor("/usr/local/bin/osis_actor")
|
||||
.sal_actor("/usr/local/bin/sal_actor")
|
||||
.v_actor("/usr/local/bin/v_actor")
|
||||
.actor_env_var("REDIS_URL", "redis://localhost:6379")
|
||||
.actor_env_var("LOG_LEVEL", "info")
|
||||
.build().await?;
|
||||
|
||||
info!("Supervisor created and workers launched successfully");
|
||||
info!("Supervisor created and actors launched successfully");
|
||||
|
||||
// Wait a moment for workers to start
|
||||
// Wait a moment for actors to start
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
|
||||
// Check worker status using the simplified API
|
||||
info!("Checking worker status...");
|
||||
let workers = supervisor.get_workers(&[]).await;
|
||||
// Check actor status using the simplified API
|
||||
info!("Checking actor status...");
|
||||
let actors = supervisor.get_actors(&[]).await;
|
||||
|
||||
for worker in &workers {
|
||||
let status_info = if worker.is_running {
|
||||
format!("Running (PID: {})", worker.status.as_ref().map(|s| s.pid).unwrap_or(0))
|
||||
for actor in &actors {
|
||||
let status_info = if actor.is_running {
|
||||
format!("Running (PID: {})", actor.status.as_ref().map(|s| s.pid).unwrap_or(0))
|
||||
} else {
|
||||
"Stopped".to_string()
|
||||
};
|
||||
info!(" Worker '{}' ({:?}): {}", worker.config.name, worker.config.script_type, status_info);
|
||||
info!(" Actor '{}' ({:?}): {}", actor.config.name, actor.config.script_type, status_info);
|
||||
}
|
||||
|
||||
// Demonstrate lifecycle operations with simplified API
|
||||
info!("=== Worker Lifecycle Operations ===");
|
||||
info!("=== Actor Lifecycle Operations ===");
|
||||
|
||||
// 1. Demonstrate restart functionality
|
||||
info!("1. Demonstrating worker restart...");
|
||||
if let Err(e) = supervisor.restart_worker("osis_worker_1").await {
|
||||
error!("Failed to restart worker: {}", e);
|
||||
info!("1. Demonstrating actor restart...");
|
||||
if let Err(e) = supervisor.restart_actor("osis_actor_1").await {
|
||||
error!("Failed to restart actor: {}", e);
|
||||
} else {
|
||||
info!(" ✅ Successfully restarted osis_worker_1");
|
||||
info!(" ✅ Successfully restarted osis_actor_1");
|
||||
}
|
||||
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
@@ -61,11 +61,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 3. Demonstrate graceful shutdown
|
||||
info!("3. Demonstrating graceful shutdown...");
|
||||
|
||||
// Stop specific workers
|
||||
if let Err(e) = supervisor.stop_worker("osis_worker_1").await {
|
||||
error!("Failed to stop worker: {}", e);
|
||||
// Stop specific actors
|
||||
if let Err(e) = supervisor.stop_actor("osis_actor_1").await {
|
||||
error!("Failed to stop actor: {}", e);
|
||||
} else {
|
||||
info!(" ✅ Worker stopped successfully");
|
||||
info!(" ✅ Actor stopped successfully");
|
||||
}
|
||||
|
||||
info!("Demo completed successfully!");
|
||||
|
@@ -1,18 +1,18 @@
|
||||
[global]
|
||||
redis_url = "redis://localhost:6379"
|
||||
|
||||
[osis_worker]
|
||||
binary_path = "/path/to/osis_worker"
|
||||
[osis_actor]
|
||||
binary_path = "/path/to/osis_actor"
|
||||
env_vars = { "VAR1" = "value1", "VAR2" = "value2" }
|
||||
|
||||
[sal_worker]
|
||||
binary_path = "/path/to/sal_worker"
|
||||
[sal_actor]
|
||||
binary_path = "/path/to/sal_actor"
|
||||
env_vars = { "VAR1" = "value1", "VAR2" = "value2" }
|
||||
|
||||
[v_worker]
|
||||
binary_path = "/path/to/v_worker"
|
||||
[v_actor]
|
||||
binary_path = "/path/to/v_actor"
|
||||
env_vars = { "VAR1" = "value1", "VAR2" = "value2" }
|
||||
|
||||
[python_worker]
|
||||
binary_path = "/path/to/python_worker"
|
||||
[python_actor]
|
||||
binary_path = "/path/to/python_actor"
|
||||
env_vars = { "VAR1" = "value1", "VAR2" = "value2" }
|
||||
|
@@ -16,14 +16,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
info!("Supervisor created.");
|
||||
|
||||
let script_content = r#"
|
||||
// This script will never be executed by a worker because the recipient does not exist.
|
||||
// This script will never be executed by a actor because the recipient does not exist.
|
||||
let x = 10;
|
||||
let y = x + 32;
|
||||
y
|
||||
"#;
|
||||
|
||||
// The worker_id points to a worker queue that doesn't have a worker.
|
||||
let non_existent_recipient = "non_existent_worker_for_timeout_test";
|
||||
// The actor_id points to a actor queue that doesn't have a actor.
|
||||
let non_existent_recipient = "non_existent_actor_for_timeout_test";
|
||||
let very_short_timeout = Duration::from_secs(2);
|
||||
|
||||
info!(
|
||||
|
Reference in New Issue
Block a user