4.1 KiB
4.1 KiB
Hero Runner
A specialized runner for the Hero ecosystem that executes heroscripts using the hero CLI tool.
Overview
The Hero runner executes heroscripts by calling hero run -h <payload> for each job. This makes it ideal for:
- Running heroscripts from job payloads
- Executing Hero automation tasks
- Integrating with the Hero CLI ecosystem
- Running scripted workflows
Features
- Heroscript Execution: Executes
hero run -h <payload>for each job - Environment Variables: Passes job environment variables to the hero command
- Timeout Support: Respects job timeout settings
- Signature Verification: Verifies job signatures before execution
- Simple Integration: No complex payload parsing - just pass the heroscript content
Usage
Starting the Runner
# Basic usage
herorunner my-hero-runner
# With custom Redis URL
herorunner my-hero-runner --redis-url redis://localhost:6379
Command-line Options
runner_id: Runner identifier (required, positional)-r, --redis-url: Redis URL (default:redis://localhost:6379)
Job Payload Format
The job payload should contain the heroscript content that will be passed to hero run -h.
Example Payload
print("Hello from heroscript!")
The runner will execute: hero run -h 'print("Hello from heroscript!")'
Examples
Example 1: Simple Heroscript
Job payload:
print("Processing job...")
Executed as: hero run -h 'print("Processing job...")'
Example 2: Multi-line Heroscript
Job payload:
print("Starting task...")
// Your heroscript logic here
print("Task completed!")
Example 3: With Environment Variables
Job with env_vars:
{
"payload": "print(env.MY_VAR)",
"env_vars": {
"MY_VAR": "Hello from Hero Runner"
}
}
Architecture
The Hero runner implements the Runner trait from hero-runner library:
┌─────────────────────┐
│ HeroExecutor │
│ │
│ - execute_command()│
│ - process_job() │
└─────────────────────┘
│
│ implements
▼
┌─────────────────────┐
│ Runner Trait │
│ │
│ - spawn() │
│ - process_job() │
│ - runner_type() │
└─────────────────────┘
│
│ executes
▼
┌─────────────────────┐
│ hero run -h │
│ <heroscript> │
└─────────────────────┘
Security Considerations
- Heroscript Execution: The runner executes heroscripts via the
heroCLI. Ensure job payloads are from trusted sources. - Signature Verification: Always verify job signatures before execution.
- Environment Variables: Be cautious with sensitive data in environment variables.
- Hero CLI Access: Ensure the
herocommand is available in the system PATH.
Error Handling
The runner handles various error scenarios:
- Hero CLI Not Found: Returns error if the
herocommand is not available - Timeout: Kills the process if it exceeds the job timeout
- Non-zero Exit: Returns error if
hero run -hexits with non-zero status - Heroscript Errors: Returns error output from the hero CLI
Logging
The runner logs to stdout/stderr with the following log levels:
INFO: Job start/completion, runner lifecycleDEBUG: Command details, parsing informationERROR: Execution failures, timeout errors
Integration with Supervisor
The Vlang runner integrates with the Hero Supervisor:
- Register the runner with the supervisor
- Supervisor queues jobs to the runner's Redis queue
- Runner polls the queue and executes commands
- Results are stored back in Redis
Development
Building
cargo build -p runner-hero
Running Tests
cargo test -p runner-hero
Running Locally
cargo run -p runner-hero -- test-runner
License
MIT OR Apache-2.0