Developer Guide

Overview

This guide provides a comprehensive overview of developing with Tasker, covering all the key components that make up the workflow engine. Tasker is designed around six main developer-facing components:

  1. TaskNamespaces & Versioning - Organize and version task handlers for scalable workflow management

  2. Task Handlers - Define and coordinate multi-step workflows

  3. Step Handlers - Implement the business logic for individual workflow steps

  4. Event Subscribers - Create integrations with external services and monitoring systems

  5. YAML Configuration - Declarative workflow and step configuration with namespace support

  6. Authentication & Authorization - Secure your workflows with flexible authentication strategies

New in Tasker 1.0.6: TaskNamespace + Versioning Architecture

Tasker now supports hierarchical task organization and semantic versioning for enterprise-scale workflow management:

Key Benefits

  • Namespace Isolation: Organize tasks by domain (payments, inventory, notifications)

  • Version Coexistence: Multiple versions of the same task can run simultaneously

  • Zero Breaking Changes: Existing tasks continue working with automatic defaults

  • Enterprise Scalability: Clean separation of concerns for large organizations

Quick Example

Namespace Organization Patterns

  • payments - Payment processing, billing, refunds

  • inventory - Stock management, fulfillment, warehouse operations

  • notifications - Email, SMS, push notifications, alerts

  • integrations - Third-party APIs, webhooks, data synchronization

  • data_processing - ETL, data transformation, analytics pipelines

  • default - General workflows (automatic fallback when unspecified)

Architecture Overview

1. TaskNamespaces & Versioning

TaskNamespaces provide organizational hierarchy for task handlers, while versioning enables multiple versions of the same task to coexist. This is essential for enterprise environments with complex workflows and deployment strategies.

TaskNamespace Management

Creating TaskNamespaces

TaskNamespaces are automatically created when referenced, but you can also create them explicitly:

Namespace Patterns & Best Practices

Domain-Based Organization:

Version Management Strategies:

HandlerFactory Registry Architecture

The HandlerFactory now uses a thread-safe 3-level registry with enterprise-grade capabilities:

Enterprise Features:

  • Thread-Safe Operations: Concurrent::Hash storage eliminates race conditions

  • Structured Logging: Every operation logged with correlation IDs

  • Interface Validation: Fail-fast validation with detailed error messages

  • Conflict Resolution: replace: true parameter for graceful updates

  • Health Monitoring: Built-in statistics and health checks

  • Event Integration: Registry operations trigger 56-event system

Registration Examples:

Versioning Best Practices

Semantic Versioning

Follow semver.org conventions:

  • Major version (2.0.0): Breaking changes, incompatible API changes

  • Minor version (1.1.0): New features, backward compatible

  • Patch version (1.0.1): Bug fixes, backward compatible

Version Lifecycle Management

2. Task Handlers

Task handlers define the overall workflow structure and coordinate step execution. They are the entry point for creating and managing multi-step processes.

Creating Task Handlers

Use the generator to create a complete task handler structure:

This creates:

  • Handler Class: app/tasks/order_process/order_handler.rb

  • YAML Configuration: config/tasker/tasks/order_process/order_handler.yaml

  • Test File: spec/tasks/order_process/order_handler_spec.rb

Task Handler Class Structure

Task Handler Capabilities

  • Workflow Orchestration: Manages step dependencies and execution order

  • Parallel Processing: Supports concurrent execution of independent steps

  • Error Handling: Comprehensive retry logic with exponential backoff

  • Context Management: Passes data between steps through task context

  • Validation: JSON schema validation plus custom business rules

  • Event Publishing: Automatic lifecycle event generation

Available Override Methods

ConfiguredTask Class Methods (for customizing configuration):

  • self.task_name - Override the default task name (defaults to class name underscored)

  • self.yaml_path - Override the default YAML configuration file path

  • self.config - Override how configuration is loaded (defaults to YAML.load_file)

TaskHandler Instance Methods (for customizing behavior):

  • establish_step_dependencies_and_defaults(task, steps) - Modify step configuration at runtime

  • update_annotations(task, sequence, steps) - Add custom annotations after step completion

  • schema - Define custom validation schema for task context (overrides YAML schema)

2. Step Handlers

Step handlers implement the specific business logic for individual workflow steps. They are the workhorses that perform the actual operations.

Step Handler Types

Base Step Handler - For general business logic with custom events:

API Step Handler - For external API integrations:

API Step Handler Implementation

The process Method - Your Extension Point:

API step handlers use the process method as the developer extension point. The framework handles all orchestration, error handling, retries, and event publishing automatically:

Making Different Types of API Requests:

Custom Response Processing:

Override the process_results method to customize how API responses are processed and stored:

Setting Results Directly in process:

You can also set step.results directly in your process method if you prefer:

Key API Step Handler Principles:

  1. Implement process method - This is your extension point for HTTP request logic

  2. Use the connection object - Pre-configured Faraday connection with retry/timeout handling

  3. Return the response - Let the framework handle response processing and error detection

  4. Override process_results for custom processing - Transform responses while preserving framework behavior

  5. Set step.results for custom data - Either in process or process_results

  6. Raise exceptions for failures - Framework handles error states and retry orchestration

  7. Never override handle - This is framework-only coordination code

Step Handler Features

  • Automatic Result Storage: Return values automatically stored in step.results

  • Context Access: Full access to task context and previous step results

  • Error Handling: Framework determines success/failure based on exceptions (see Error Handling Patterns in Best Practices)

  • Custom Processing: Override process_results for custom result handling

  • Event Integration: Automatic event publishing for observability

Accessing Previous Step Data

3. Event Subscribers

Event subscribers handle "collateral" or "secondary" logic - operations that support observability, monitoring, and alerting but are not core business requirements. They respond to workflow events and provide operational visibility into system behavior.

Architectural Distinction: Subscribers vs Steps

Event Subscribers are for collateral concerns:

  • Operational Observability: Logging, metrics, telemetry, traces

  • Alerting & Monitoring: Sentry errors, PagerDuty alerts, operational notifications

  • Analytics: Business intelligence, usage tracking, performance monitoring

  • External Integrations: Non-critical third-party service notifications

Workflow Steps are for business-critical operations requiring:

  • Idempotency: Can be safely retried without side effects

  • Retryability: Built-in retry logic with exponential backoff

  • Explicit Lifecycle Tracking: Success/failure states that matter to the business

  • Transactional Integrity: Operations that need to be rolled back on failure

Rule of Thumb: If the operation must succeed for the workflow to be considered complete, it should be a workflow step. If it's supporting infrastructure (logging, monitoring, analytics), it should be an event subscriber.

Creating Event Subscribers

Use the generator to create subscribers with automatic method routing:

Event Subscriber Structure

Available Events

Discover all available events using the event catalog:

Real-World Integration Examples

Metrics Collection (DataDog):

Error Tracking (Sentry):

4. YAML Configuration

YAML files provide declarative configuration for task handlers, defining workflows, dependencies, and step settings without requiring code changes.

Task Handler YAML Structure

Advanced YAML Features

Multiple Dependencies:

Environment-Specific Configuration:

API Step Configuration:

TaskNamespace + Versioning in YAML

The new namespace and versioning system provides enterprise-scale organization:

Namespace-Based File Organization

Recommended File Structure:

Version Coexistence Examples

Multiple Versions of Same Task:

Namespace-Specific Configuration

Domain-Specific Settings:

Configuration Validation & Defaults

YAML Configuration Schema:

Migration Strategy for Existing Configurations

Backward Compatibility: Existing YAML files continue working unchanged:

5. Authentication & Authorization

Tasker provides a comprehensive, production-ready authentication and authorization system that works with any Rails authentication solution. The system uses dependency injection and resource-based authorization to provide enterprise-grade security for both REST APIs and GraphQL endpoints.

Key Features

  • Provider Agnostic: Works with Devise, JWT, OmniAuth, custom authentication, or no authentication

  • Resource-Based Authorization: Granular permissions using resource:action patterns (e.g., tasker.task:create)

  • GraphQL Operation-Level Authorization: Revolutionary security for GraphQL that maps operations to resource permissions

  • Automatic Controller Integration: Authentication and authorization work seamlessly across REST and GraphQL

  • Comprehensive Generators: Create production-ready authenticators and authorization coordinators

  • Zero Breaking Changes: All features are opt-in and backward compatible

Quick Configuration Example

Available Generators

GraphQL Authorization Example

The system automatically maps GraphQL operations to resource permissions:

Resource-Based Permissions

Authorization uses a simple resource:action permission model:

Complete Documentation

For comprehensive documentation including:

  • Quick Start Guides - Get authentication working in minutes

  • Custom Authenticator Examples - JWT, Devise, API tokens, and more

  • Authorization Coordinator Patterns - Role-based, context-aware, and time-based authorization

  • GraphQL Authorization Details - Operation mapping and context handling

  • Production Best Practices - Security, performance, and monitoring guidelines

  • Testing Strategies - Complete test examples and isolation techniques

See Authentication & Authorization Guide for complete documentation.

6. Multi-Database Support

Tasker provides optional multi-database support using Rails' standard multi-database conventions. This allows Tasker models to use a separate database from the host application for data isolation, performance, or compliance requirements.

Key Features

  • Rails Multi-Database Integration: Uses Rails' connects_to API following official conventions

  • Standard Configuration: Leverages Rails database.yml patterns with named databases

  • Automatic Model Support: All Tasker models inherit multi-database capability automatically

  • Zero Breaking Changes: Fully backward compatible with existing installations

  • Environment-Specific: Supports different database configurations per environment

Configuration

Database Configuration

Benefits of Multi-Database Setup

Data Isolation: Separate Tasker data from application data for security or compliance

Performance: Dedicated database resources for workflow processing

Scaling: Independent scaling of workflow database based on usage patterns

Backup Strategy: Separate backup and recovery policies for workflow data

Development: Easier testing and development with isolated workflow data

Migration Support

When using a secondary database, Tasker migrations automatically target the correct database:

Production Considerations

  • Connection Pooling: Configure appropriate connection pool sizes for both databases

  • Monitoring: Monitor connection usage and performance for both databases

  • Backup Strategy: Implement coordinated backup strategies if data consistency across databases is required

  • Network Latency: Consider network latency if databases are on different servers

7. Dependency Graph & Bottleneck Analysis Configuration

Tasker provides advanced dependency graph analysis and bottleneck detection capabilities that can be fine-tuned for your specific workflow patterns. The dependency graph configuration controls how Tasker analyzes workflow dependencies, identifies bottlenecks, and calculates impact scores for optimization recommendations.

Key Features

  • Configurable Impact Scoring: Customize how different factors influence bottleneck calculations

  • Adaptive Severity Classification: Define custom thresholds for Critical/High/Medium/Low priority bottlenecks

  • Dynamic Duration Estimation: Configure time estimates for path analysis and planning

  • State-Based Multipliers: Adjust scoring based on step states and execution conditions

  • Retry Pattern Analysis: Configure penalties for instability and failure patterns

Quick Configuration Example

Configuration Options

Impact Multipliers

Control how different factors contribute to the overall bottleneck impact score:

Impact Score Calculation:

Severity Multipliers

Adjust impact scores based on step states and execution conditions:

State-Based Scoring Examples:

  • Normal step: base_score * 1.0

  • Error step: base_score * 2.0

  • Error step with exhausted retries: base_score * (2.0 + 0.5) = base_score * 2.5

  • Dependency blocked step: base_score * 1.2

Penalty Constants

Add fixed penalty points for specific problematic conditions:

Penalty Application:

  • Step with 2 retry attempts: +6 penalty points

  • Non-retryable failure: +10 penalty points

  • Exhausted retries (3+ attempts): +20 penalty points

Severity Thresholds

Define score ranges for bottleneck classification:

Classification Examples:

  • Score 150: Critical - Blocking multiple workflows, immediate intervention required

  • Score 75: High - Significant impact, should be addressed in current sprint

  • Score 35: Medium - Moderate impact, address in upcoming planning cycle

  • Score 10: Low - Minor impact, monitor for trends

Duration Estimates

Configure time estimates for path analysis and planning:

Duration Calculation:

Use Cases & Recommendations

High-Volume Transaction Processing

For workflows processing thousands of transactions per hour:

Long-Running Batch Processes

For workflows that run for hours or days:

Real-Time Processing Systems

For workflows requiring sub-second response times:

Monitoring & Observability

The dependency graph analysis integrates with Tasker's observability system to provide actionable insights:

Production Best Practices

  1. Start with Defaults: Begin with default values and adjust based on observed patterns

  2. Monitor Thresholds: Track how often each severity level is triggered

  3. A/B Testing: Test configuration changes on a subset of workflows first

  4. Gradual Tuning: Make small adjustments and measure impact over time

  5. Documentation: Document your configuration rationale for team knowledge

The dependency graph configuration provides powerful tools for optimizing workflow performance while maintaining the flexibility to adapt to your specific operational requirements.

8. Cache Strategy & Custom Store Capabilities

Tasker includes a Hybrid Cache Detection System that provides intelligent cache strategy selection and supports both built-in Rails cache stores and custom cache implementations. This system automatically adapts coordination strategies based on cache store capabilities, ensuring optimal performance across different deployment environments.

Key Features

  • 🎯 Developer-Friendly API: Declarative capability system for custom cache stores

  • πŸš€ Performance Optimized: Frozen constants provide O(1) lookup for built-in stores

  • πŸ”„ Hybrid Detection: Priority-based detection system (declared β†’ constants β†’ custom β†’ runtime)

  • πŸ“Š Production-Ready: Comprehensive structured logging and error handling

  • ⚑ Rails Integration: Always uses Rails.cache as the source of truth

Quick Example

Architecture Overview

The cache detection system uses a 4-level priority hierarchy:

Built-in Store Support

Tasker includes frozen constants for fast, reliable detection of official Rails cache stores:

Coordination Strategies by Store Type:

  • Redis/SolidCache: distributed_atomic (full distributed coordination with locking)

  • Memcached: distributed_basic (distributed coordination without locking)

  • Memory/File/Null: local_only (single-process coordination)

Custom Cache Store Integration

Using CacheCapabilities Module

The Tasker::CacheCapabilities module provides a clean API for declaring your cache store's capabilities:

Capability Reference

Capability
Description
Impact

distributed

Cache is shared across processes/containers

Enables distributed coordination

atomic_increment

Supports atomic increment/decrement operations

Enables optimistic locking patterns

locking

Supports distributed locking (with_lock)

Enables distributed_atomic strategy

ttl_inspection

Can inspect/extend TTL of cached entries

Enables advanced TTL management

namespace_support

Supports cache key namespacing

Enables namespace isolation

compression_support

Supports automatic value compression

Enables bandwidth optimization

Chaining and Inheritance

Advanced Usage Patterns

Custom Detector Registration

For complex detection logic that can't be expressed through simple capability declarations:

Runtime Strategy Inspection

Production Monitoring

The cache strategy system includes comprehensive structured logging:

Best Practices

Cache Store Selection

For High-Performance Applications:

For Development/Testing:

For Legacy Memcached:

Testing Custom Stores

Migration Guide

Upgrading Existing Custom Stores

If you have existing custom cache stores, add capability declarations:

Backwards Compatibility

The system maintains full backwards compatibility:

  • Undeclared stores: Fall back to runtime pattern detection

  • Existing configurations: Continue working without changes

  • Built-in stores: Automatically detected with frozen constants

The cache strategy system provides a robust foundation for building cache-aware applications that adapt intelligently to different deployment environments while maintaining optimal performance characteristics.

Extensibility & Advanced Patterns

Custom Step Handler Types

Beyond the built-in Base and Api step handlers, you can create specialized step handler types for common patterns in your application:

Custom Event Publishing Patterns

Create reusable event publishing patterns for consistent observability:

Advanced Configuration Patterns

Environment-Specific Step Configuration:

Dynamic Step Generation:

Custom Workflow Coordination

Priority-Based Step Execution:

Resource-Aware Execution:

Custom Result Processing

Structured Result Schemas:

Result Transformation Pipelines:

Task Execution & Orchestration

For detailed understanding of Tasker's sophisticated orchestration patterns, including the dual finalization strategy and coordinated vs autonomous execution contexts, see:

πŸ“– Task Execution Control Flow - Comprehensive documentation of workflow orchestration patterns, synchronous vs asynchronous finalization, and the coordination between WorkflowCoordinator and TaskFinalizer components.

Best Practices

Task Handler Design

  1. Single Responsibility: Each task handler should represent one business process

  2. Meaningful Names: Use descriptive names that clearly indicate the workflow purpose

  3. Proper Dependencies: Define clear step dependencies that reflect business logic

  4. Error Handling: Configure appropriate retry limits based on operation reliability

  5. Context Design: Include all necessary data in task context for step execution

  6. Extensibility: Design task handlers to support configuration-driven customization

Step Handler Implementation

  1. Focused Logic: Each step should do one thing well

  2. Clear Results: Return meaningful data structure for dependent steps

  3. Error Handling: Understand how the framework determines step success/failure (see Error Handling Patterns below)

  4. Idempotency: Design steps to be safely retryable

  5. Resource Cleanup: Clean up resources in error scenarios

Error Handling Patterns

The framework determines step success/failure based on whether the process method raises an exception:

  • Exception raised β†’ Step marked as FAILED, retry logic triggered, workflow stops

  • No exception raised β†’ Step marked as COMPLETED, workflow continues

Pattern 1: Let exceptions bubble up (Recommended)

Pattern 2: Catch, record error details, then re-raise

Pattern 3: Treat handled exceptions as success

⚠️ Important: Only catch exceptions in your process method if you intend to either:

  • Add custom error context to step.results and re-raise (Pattern 2)

  • Treat the exception as a recoverable success case (Pattern 3)

Never catch an exception, return error data, and expect the framework to treat it as a failure - it will be marked as successful.

Event Subscriber Guidelines

  1. Extend BaseSubscriber: Always use Tasker::Events::Subscribers::BaseSubscriber

  2. Safe Data Access: Use safe_get(event, :key, default) for robust data access

  3. Error Isolation: Don't let subscriber errors break task execution

  4. Async Operations: Move heavy operations to background jobs

  5. Monitoring: Monitor subscriber performance and error rates

YAML Configuration Management

  1. Environment Separation: Use environment-specific configurations appropriately

  2. Sensitive Data: Use environment variables for secrets and API keys

  3. Documentation: Include clear descriptions for all steps

  4. Validation: Use JSON schema validation for task context requirements

  5. Versioning: Version control all YAML configuration files

Development Workflow

1. Plan Your Workflow

2. Generate Task Handler

3. Implement Step Handlers

4. Configure Dependencies

5. Test Your Workflow

6. Deploy and Monitor

  • Custom events are automatically registered and discoverable

  • External systems can subscribe to your custom events

  • Monitor workflow execution through event subscriptions

Testing Strategies

Testing Task Handlers

Testing Step Handlers

Testing Event Subscribers

Integration Validation & Production Readiness

Tasker includes comprehensive integration validation scripts that prove production readiness through real-world testing of the complete observability stack. These scripts are essential for validating enterprise deployments and ensuring reliable metrics collection and distributed tracing.

Validation Script Architecture

The validation scripts (scripts/validate_*.rb) provide enterprise-grade validation of Tasker's integration with observability stack components:

Jaeger Integration Validator (validate_jaeger_integration.rb)

Validates OpenTelemetry distributed tracing integration:

Validation Categories:

  • Connection Testing: Verifies Jaeger HTTP API connectivity

  • Workflow Execution: Creates and executes real workflow patterns (linear, diamond, parallel)

  • Trace Collection: Validates trace export and collection in Jaeger

  • Span Hierarchy: Analyzes parent-child relationships across workflow steps

  • Trace Correlation: Ensures proper trace correlation across distributed operations

Sample Results:

Prometheus Integration Validator (validate_prometheus_integration.rb)

Validates metrics collection and Prometheus integration:

Validation Categories:

  • Prometheus Connection: Verifies Prometheus server connectivity

  • Metrics Endpoint: Tests Tasker's /tasker/metrics endpoint

  • Workflow Execution: Executes workflows to generate authentic metrics

  • Metrics Collection: Validates event-driven metrics collection via EventRouter

  • Query Validation: Tests PromQL queries for dashboard compatibility

  • Performance Analysis: Analyzes TSDB integration and performance

Sample Results:

Event-Driven Architecture Validation

The validation scripts prove Tasker's sophisticated event-driven architecture:

Critical Technical Breakthrough: MetricsSubscriber

The Prometheus validator discovered and resolved a critical missing component in Tasker's metrics architecture:

Problem: Events were being published via Events::Publisher and creating OpenTelemetry spans via TelemetrySubscriber, but no metrics were being collected because there was no bridge between the event system and the EventRouter β†’ MetricsBackend system.

Solution: Created MetricsSubscriber that bridges events to the EventRouter:

Integration: The MetricsSubscriber is now automatically registered in the Orchestration::Coordinator alongside the TelemetrySubscriber, ensuring complete observability coverage.

Production Deployment Validation

Prerequisites for Validation

Continuous Integration Integration

Both scripts are designed for CI/CD pipelines:

Enterprise Deployment Checklist

Pre-Deployment Validation:

Post-Deployment Monitoring:

Development Workflow Integration

Local Development Setup

Debugging Integration Issues

The validation scripts provide comprehensive diagnostics:

Common Issues & Solutions:

  • No Metrics Collected: Ensure MetricsSubscriber is registered (automatic in Tasker 1.0.6+)

  • Missing Spans: Verify OpenTelemetry exporter configuration

  • Connection Failures: Check service ports and network connectivity

  • Query Failures: Validate Prometheus data retention and configuration

Strategic Value

The integration validation scripts provide:

  • 🎯 Production Confidence: Comprehensive proof of enterprise readiness

  • πŸ”§ Developer Experience: Clear validation results with actionable feedback

  • πŸ“Š Integration Foundation: Proven patterns for observability stack integration

  • πŸ“ˆ Content Creation: Technical excellence provides foundation for documentation and presentations

  • πŸš€ Enterprise Adoption: Validated observability enables confident production deployment

Status: COMPLETE - Both Jaeger and Prometheus integration validators fully implemented and tested with 100% success rates, proving Tasker's production readiness through comprehensive observability stack validation.

Application Template Validation

Tasker includes a comprehensive dry-run validation system for application template generation that ensures template consistency and correctness without generating files. This system is essential for maintaining template quality and CI/CD pipeline integration.

Dry-Run Validation Overview

The validation system tests five critical categories of template correctness:

Validation Categories

1. Template File Existence Validation

  • Verifies all required ERB templates exist for selected task types

  • Adapts template requirements based on Docker/observability modes

  • Reports missing templates with specific file paths

2. ERB Template Syntax Validation

  • Parses all ERB templates for syntax errors using ERB.new(template).check_syntax

  • Validates template structure without executing Ruby code

  • Catches malformed ERB blocks and Ruby expressions

3. Generated Code Syntax Validation

  • Renders templates with test data to validate actual output

  • Uses RubyVM::InstructionSequence.compile for Ruby syntax validation

  • Uses YAML.safe_load for YAML syntax validation

  • Tests real generated output, not just template correctness

4. CLI Options Mapping Validation

  • Ensures all Thor CLI options have corresponding instance variables

  • Validates option-to-variable mapping (e.g., --docker β†’ @docker_mode)

  • Checks for missing or incorrectly mapped CLI options

5. Template Variable Bindings Validation

  • Tests template rendering with expected binding contexts

  • Validates all required variables are available during rendering

  • Tests step handlers, configuration files, and Docker-specific bindings

CI/CD Integration

The dry-run validation system is designed for continuous integration:

Development Workflow Integration

Template Development Process:

  1. Modify ERB templates in scripts/templates/

  2. Run dry-run validation to catch issues early

  3. Fix validation errors before committing

  4. CI/CD pipeline validates all template combinations

Local Development Validation:

Performance Characteristics

  • Zero File System Impact: No files created during validation

  • Sub-second Execution: Validation completes in under 1 second

  • Clear Exit Codes: 0 for success, 1 for failure (CI/CD friendly)

  • Detailed Error Reporting: Specific file paths and line numbers for errors

Strategic Benefits

  • Template Quality Assurance: Prevents broken templates from reaching production

  • Developer Confidence: Comprehensive validation reduces template-related issues

  • CI/CD Integration: Automated validation in deployment pipelines

  • Rapid Feedback: Immediate validation results during development

  • Enterprise Reliability: Ensures consistent template generation across environments

Last updated