Files
supervisor/examples/_archive/supervisor
Timur Gordon 98b2718d58 feat: simplify OpenRPC API and reorganize examples
- Simplified RunnerConfig to just name, command, and optional env
- Removed RunnerType and ProcessManagerType enums
- Removed db_path, redis_url, binary_path from config
- Made runner name also serve as queue name (no separate queue param)
- Added secret-based authentication to all runner management methods
- Created comprehensive osiris_openrpc example
- Archived old examples to _archive/
- Updated client API to match simplified supervisor interface
2025-10-27 14:20:40 +01:00
..

Hero Supervisor Example

This example demonstrates how to configure and run the Hero Supervisor with multiple actors using a TOML configuration file.

Files

  • config.toml - Example supervisor configuration with multiple actors
  • run_supervisor.sh - Shell script to build and run the supervisor with the example config
  • run_supervisor.rs - Rust script using escargot to build and run the supervisor
  • README.md - This documentation file

Configuration

The config.toml file defines:

  • Redis connection: URL for the Redis server used for job queuing
  • Database path: Local path for supervisor state storage
  • Job queue key: Redis key for the supervisor job queue
  • Actors: List of actor configurations with:
    • name: Unique identifier for the actor
    • runner_type: Type of runner ("SAL", "OSIS", "V", "Python")
    • binary_path: Path to the actor binary
    • process_manager: Process management type ("simple" or "tmux")

Prerequisites

  1. Redis Server: Ensure Redis is running on localhost:6379 (or update the config)
  2. Actor Binaries: Build the required actor binaries referenced in the config:
    # Build SAL worker
    cd ../../sal
    cargo build --bin sal_worker
    
    # Build OSIS and system workers
    cd ../../worker
    cargo build --bin osis
    cargo build --bin system
    

Running the Example

./run_supervisor.sh

Option 2: Rust Script with Escargot

cargo +nightly -Zscript run_supervisor.rs

Option 3: Manual Build and Run

# Build the supervisor
cd ../../../supervisor
cargo build --bin supervisor --features cli

# Run with config
./target/debug/supervisor --config ../baobab/examples/supervisor/config.toml

Usage

Once running, the supervisor will:

  1. Load the configuration from config.toml
  2. Initialize and start all configured actors
  3. Listen for jobs on the Redis queue (hero:supervisor:jobs)
  4. Dispatch jobs to appropriate actors based on the runner field
  5. Monitor actor health and status

Testing

You can test the supervisor by dispatching jobs to the Redis queue:

# Using redis-cli to add a test job
redis-cli LPUSH "hero:supervisor:jobs" '{"id":"test-123","runner":"sal_actor_1","script":"print(\"Hello from SAL actor!\")"}'

Stopping

Use Ctrl+C to gracefully shutdown the supervisor. It will:

  1. Stop accepting new jobs
  2. Wait for running jobs to complete
  3. Shutdown all managed actors
  4. Clean up resources

Customization

Modify config.toml to:

  • Add more actors
  • Change binary paths to match your build locations
  • Update Redis connection settings
  • Configure different process managers per actor
  • Adjust database and queue settings

Troubleshooting

  • Redis Connection: Ensure Redis is running and accessible
  • Binary Paths: Verify all actor binary paths exist and are executable
  • Permissions: Ensure the supervisor has permission to create the database directory
  • Ports: Check that Redis port (6379) is not blocked by firewall