Class: Tasker::Analysis::RuntimeGraphAnalyzer
- Inherits:
-
Object
- Object
- Tasker::Analysis::RuntimeGraphAnalyzer
- Defined in:
- lib/tasker/analysis/runtime_graph_analyzer.rb
Overview
Runtime Graph Analyzer for Workflow Dependencies
Provides comprehensive analysis of workflow step dependencies, execution flow, and performance bottlenecks using database-backed graph analysis. Leverages existing SQL functions for optimal performance and consistency.
Instance Attribute Summary collapse
-
#task ⇒ Tasker::Task
readonly
The task being analyzed.
-
#task_id ⇒ Integer
readonly
The task ID for database queries.
Instance Method Summary collapse
-
#analyze ⇒ Hash
Perform comprehensive workflow analysis.
-
#build_dependency_graph ⇒ Hash
Build complete dependency graph structure.
-
#clear_cache! ⇒ void
Clear all cached analysis results.
-
#initialize(task:) ⇒ RuntimeGraphAnalyzer
constructor
Initialize the analyzer for a specific task.
Constructor Details
#initialize(task:) ⇒ RuntimeGraphAnalyzer
Initialize the analyzer for a specific task
35 36 37 38 39 40 |
# File 'lib/tasker/analysis/runtime_graph_analyzer.rb', line 35 def initialize(task:) @task = task @task_id = task.task_id @cache = {} @intelligent_cache = Tasker::Telemetry::IntelligentCacheManager.new end |
Instance Attribute Details
#task ⇒ Tasker::Task (readonly)
Returns The task being analyzed.
26 27 28 |
# File 'lib/tasker/analysis/runtime_graph_analyzer.rb', line 26 def task @task end |
#task_id ⇒ Integer (readonly)
Returns The task ID for database queries.
29 30 31 |
# File 'lib/tasker/analysis/runtime_graph_analyzer.rb', line 29 def task_id @task_id end |
Instance Method Details
#analyze ⇒ Hash
Perform comprehensive workflow analysis
Returns a complete analysis of the workflow including dependency graphs, critical paths, parallelism opportunities, error chains, and bottlenecks. Results are cached using IntelligentCacheManager with adaptive TTL.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tasker/analysis/runtime_graph_analyzer.rb', line 59 def analyze # Use intelligent caching for expensive workflow analysis cache_key = "tasker:analysis:runtime_graph:#{task_id}:#{task_analysis_cache_version}" @intelligent_cache.intelligent_fetch(cache_key, base_ttl: 90.seconds) do { dependency_graph: build_dependency_graph, critical_paths: analyze_critical_paths, parallelism_opportunities: analyze_parallelism, error_chains: analyze_error_chains, bottlenecks: identify_bottlenecks, generated_at: Time.current, task_id: task_id } end end |
#build_dependency_graph ⇒ Hash
Build complete dependency graph structure
Constructs a comprehensive graph representation of workflow step dependencies using database edges and SQL-based topological sorting for optimal performance.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/tasker/analysis/runtime_graph_analyzer.rb', line 107 def build_dependency_graph steps = load_workflow_steps step_map = steps.index_by(&:workflow_step_id) edges = load_workflow_edges adjacency_lists = build_adjacency_lists(steps, edges) dependency_levels = calculate_dependency_levels_sql { nodes: build_graph_nodes(steps, dependency_levels), edges: build_graph_edges(edges, step_map), adjacency_list: adjacency_lists[:forward], reverse_adjacency_list: adjacency_lists[:reverse], dependency_levels: dependency_levels } end |
#clear_cache! ⇒ void
This method returns an undefined value.
Clear all cached analysis results
Forces fresh analysis on next call to #analyze. Useful when task state has changed and you need updated analysis.
82 83 84 85 86 87 88 89 |
# File 'lib/tasker/analysis/runtime_graph_analyzer.rb', line 82 def clear_cache! @cache.clear # Clear intelligent cache for this task cache_key = "tasker:analysis:runtime_graph:#{task_id}:#{task_analysis_cache_version}" @intelligent_cache.clear_performance_data(cache_key) Rails.cache.delete(cache_key) end |