This enhancement adds multi-threaded execution capabilities to the Maestro task orchestrator, allowing users to run multiple DAGs concurrently while maintaining proper thread isolation and comprehensive lifecycle management.
- Parallel Processing: Multiple DAGs can be executed simultaneously in separate threads
- Thread Isolation: Each DAG runs in its own thread with proper resource isolation
- Thread Pool Management: Uses
ThreadPoolExecutorfor efficient thread management (max 10 concurrent DAGs)
- Thread-Safe Operations: All database operations are protected with reentrant locks
- Execution Tracking: Comprehensive tracking of DAG executions with unique execution IDs
- Timestamp Tracking: Started and completed timestamps for both DAGs and individual tasks
- Thread Identification: Each operation is tagged with thread ID for debugging and monitoring
A new maestro-concurrent CLI provides comprehensive DAG management:
run-async: Execute DAGs asynchronously in background threadsmonitor: Real-time monitoring of DAG execution with live updatesstatus: Check status of specific DAGs or all running DAGslogs: View execution logs with thread identificationvalidate: Validate DAG files and show structurelist-dags: List all DAGs in the database with their execution history
- Thread-Safe Database Operations: All methods use reentrant locks
- Enhanced Schema: New tables for execution tracking and logging
- Execution Management: Create, update, and query DAG execution records
- Logging Integration: Centralized logging with thread identification
- Thread Pool Integration: Uses
ThreadPoolExecutorfor concurrent execution - Execution ID Management: Unique execution IDs for each DAG run
- Thread-Safe Execution: Proper database connection handling in threads
- Enhanced Error Handling: Comprehensive error management across threads
- Asynchronous Execution: Background DAG execution with immediate feedback
- Real-Time Monitoring: Live status updates with Rich UI components
- Comprehensive Status: Detailed execution information and task tracking
- Log Management: Thread-aware logging and retrieval
-
task_status: Task execution status with timestamps and thread IDs
dag_id: Unique identifier for the DAGtask_id: Unique identifier for the task within the DAGstatus: Current status (pending, running, completed, failed)started_at: Timestamp when task startedcompleted_at: Timestamp when task completedthread_id: Thread identifier for debugging
-
dag_executions: DAG execution tracking with lifecycle management
dag_id: Unique identifier for the DAGexecution_id: Unique identifier for this execution instancestatus: Current status (running, completed, failed, cancelled)started_at: Timestamp when execution startedcompleted_at: Timestamp when execution completedthread_id: Thread identifier for debuggingpid: Process identifier
-
execution_logs: Centralized logging with thread identification
id: Auto-incrementing primary keydag_id: Associated DAG identifierexecution_id: Associated execution identifiertask_id: Associated task identifier (nullable)level: Log level (INFO, WARNING, ERROR, DEBUG)message: Log message contenttimestamp: When the log was createdthread_id: Thread identifier for debugging
# Start a DAG asynchronously
maestro-concurrent run-async my_dag.yaml
# Monitor execution in real-time
maestro-concurrent monitor my_dag_id
# Check status of all running DAGs
maestro-concurrent status
# View execution logs
maestro-concurrent logs my_dag_id# Resume a DAG from checkpoint
maestro-concurrent run-async my_dag.yaml --resume
# Run without failing fast
maestro-concurrent run-async my_dag.yaml --no-fail-fast
# Monitor specific execution
maestro-concurrent monitor my_dag_id --execution-id abc123
# View limited logs
maestro-concurrent logs my_dag_id --limit 50
# Show summary statistics
maestro-concurrent summary
# List all DAGs
maestro-concurrent list-dags
# List only failed DAGs
maestro-concurrent list-dags --status failed
# Show execution history for a specific DAG
maestro-concurrent history my_dag_id --limit 5
# Clean up old executions (dry run)
maestro-concurrent cleanup --days 30 --dry-run
# Cancel a running DAG
maestro-concurrent cancel my_dag_id# View comprehensive statistics
maestro-concurrent summary
# Filter DAGs by status
maestro-concurrent list-dags --status running
maestro-concurrent list-dags --status completed
maestro-concurrent list-dags --status failed
maestro-concurrent list-dags --status cancelled
# View execution history with duration calculations
maestro-concurrent history my_dag_id
# Clean up old records
maestro-concurrent cleanup --days 7 # Remove records older than 7 days
# Cancel specific execution
maestro-concurrent cancel my_dag_id --execution-id abc123- Reentrant Locks: All database operations use
threading.RLock() - Connection Management: Proper SQLite connection handling with WAL mode
- Atomic Operations: Database transactions ensure data consistency
- Thread Pool: Limited to 10 concurrent threads to prevent resource exhaustion
- Connection Pooling: Efficient database connection management
- Cleanup: Proper resource cleanup on thread completion
- Thread-Specific Errors: Errors are isolated to individual threads
- Comprehensive Logging: All errors are logged with thread context
- Graceful Degradation: Failed DAGs don't affect other running DAGs
All existing tests pass with the new multi-threaded implementation:
- Database persistence tests
- DAG execution tests
- Error handling tests
- Resume functionality tests
- Increased Throughput: Multiple DAGs can execute simultaneously
- Better Resource Utilization: Efficient use of system resources
- Improved User Experience: Real-time monitoring and status updates
- Enhanced Debugging: Thread-aware logging and comprehensive status tracking
- Scalability: Foundation for future distributed execution capabilities
- Distributed Execution: Extend to multiple nodes
- Resource Limits: Per-DAG resource constraints
- Priority Scheduling: DAG execution prioritization
- Web Interface: Browser-based monitoring and control
- Metrics Collection: Performance and execution metrics
The enhancement maintains full backward compatibility:
- Existing CLI commands continue to work unchanged
- Database schema is automatically upgraded
- All existing functionality remains intact
- New features are opt-in through the new CLI interface