System Overview
Tasker is a production-ready workflow orchestration engine built for Ruby on Rails applications. It provides robust task management, dependency resolution, and distributed system coordination through a declarative workflow definition approach.
Core Architecture
Registry System Architecture
Tasker's registry systems provide enterprise-grade capabilities for managing task handlers, plugins, and event subscribers:
Thread-Safe Registry Operations
All registry systems use Concurrent::Hash for thread-safe operations:
# HandlerFactory - Thread-safe task handler management
Tasker::HandlerFactory.instance.register(
'payment_processor',
PaymentHandler,
namespace_name: 'payments',
version: '2.1.0',
replace: true # Graceful conflict resolution
)
# PluginRegistry - Format-based plugin discovery
Tasker::Telemetry::PluginRegistry.register(
'custom_exporter',
CustomExporter,
format: :json,
replace: true
)
# SubscriberRegistry - Event subscriber management
Tasker::Registry::SubscriberRegistry.register(
'notification_subscriber',
NotificationSubscriber,
events: ['task.completed', 'task.failed']
)Structured Logging and Observability
Registry operations include comprehensive structured logging with correlation IDs:
Interface Validation & Error Handling
Comprehensive validation prevents runtime errors:
Registry Statistics & Health Monitoring
Built-in monitoring and statistics:
Event System Architecture
Tasker features a comprehensive event-driven architecture that provides both deep observability and powerful developer integration capabilities:
Event Categories
Task Events (
Tasker::Constants::TaskEvents) - Task lifecycle events (started, completed, failed)Step Events (
Tasker::Constants::StepEvents) - Step execution events with error contextWorkflow Events (
Tasker::Constants::WorkflowEvents) - Orchestration and dependency managementObservability Events (
Tasker::Constants::ObservabilityEvents) - Performance monitoring and metrics
Event Discovery and Integration
The event system includes a comprehensive catalog for discovering and understanding events:
Custom Event Subscribers
Create custom integrations with external services using the subscriber generator:
This creates a complete subscriber class with automatic method routing:
Publishing Events
OpenTelemetry Integration
Comprehensive observability stack including:
Database Query Monitoring - PostgreSQL instrumentation with connection safety
Background Job Tracking - Sidekiq, Redis, and concurrent processing
API Call Tracing - HTTP requests with proper error handling
State Machine Transitions - Complete audit trail of workflow state changes
For detailed telemetry configuration, see TELEMETRY.md.
Workflow Configuration
YAML-Based Task Definition
Tasks are defined using declarative YAML configuration:
Environment-Specific Configuration
Tasker supports environment-specific configuration overrides:
Configuration is merged at runtime, with environment-specific settings taking precedence over base configuration. This supports:
Different API endpoints per environment
Debug mode enablement in development
Secure credential management in production
REST API Interface
Tasker provides a comprehensive RESTful API for task management:
Task Management
GET /tasker/tasks- List all tasksPOST /tasker/tasks- Create and enqueue a new taskGET /tasker/tasks/{task_id}- Get task detailsPATCH/PUT /tasker/tasks/{task_id}- Update taskDELETE /tasker/tasks/{task_id}- Cancel task
Workflow Step Management
GET /tasker/tasks/{task_id}/workflow_steps- List steps for a taskGET /tasker/tasks/{task_id}/workflow_steps/{step_id}- Get step detailsPATCH/PUT /tasker/tasks/{task_id}/workflow_steps/{step_id}- Update stepDELETE /tasker/tasks/{task_id}/workflow_steps/{step_id}- Cancel step
Task Visualization
GET /tasker/tasks/{task_id}/diagram- Get a diagram for a task
Creating Tasks via API
Example task creation:
Required fields:
name: Task handler identifiercontext: Task context datainitiator: Task initiatorreason: Task creation reasonsource_system: Source system identifiertags: (Optional) Categorization tags
Workflow Execution and Orchestration
Orchestration Features
DAG Traversal & Parallel Execution
Initial identification and queueing of root steps (no dependencies)
Parallel execution of independent steps at each level
Dynamic discovery of next executable steps as dependencies are satisfied
Continuous monitoring of dependency status to activate pending steps
Automatic task completion detection when all steps are finished
Exponential Backoff Retry Logic
Base delay that doubles with each attempt:
base_delay * (2^attempt)Random jitter to prevent thundering herd problems
Configurable maximum delay cap (30 seconds)
Respects server-provided Retry-After headers when available
Production-Ready Error Handling & Persistence
Complete step error persistence with full error context, backtrace, and attempt tracking
Atomic transactions with save-first, transition-second pattern ensuring data integrity
Memory-safe processing with database connection pooling and explicit cleanup
Comprehensive event publishing for both success and error paths
Zero data loss with proper persistence of all step executions
Task Status Management
Real-time monitoring of all step statuses with unified event system
Early failure detection and propagation with comprehensive error data
Graceful handling of unrecoverable errors with full audit trail
OpenTelemetry integration for complete observability
Production Features
Thread-safe registry systems with structured logging
Unified event system with standardized event payloads
Complete step error persistence with atomic transactions
Production-ready OpenTelemetry integration with safety mechanisms
Memory-safe operation with database connection pooling
Developer-friendly API with clean integration patterns
For detailed orchestration patterns and control flow, see Task Execution Control Flow.
For comprehensive API documentation, see REST API Reference.
For complete event system documentation, see EVENT_SYSTEM.md.
Last updated