Class: Tasker::Analysis::TemplateGraphAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/tasker/analysis/template_graph_analyzer.rb

Overview

Analyzes step template dependencies for workflow design validation

This class provides comprehensive analysis of step template dependencies, including cycle detection, topological sorting, and dependency visualization. It's designed to help with workflow design validation and troubleshooting.

The analyzer performs static analysis on step templates to identify potential issues before workflow execution, including circular dependencies, dependency depth analysis, and parallel execution opportunities.

Examples:

Basic usage

analyzer = TemplateGraphAnalyzer.new(handler.step_templates)
graph = analyzer.analyze
puts "Cycles detected: #{graph[:cycles].any?}"

Checking for specific issues

analyzer = TemplateGraphAnalyzer.new(templates)
if analyzer.has_cycles?
  puts "Circular dependencies found: #{analyzer.cycles}"
end

Since:

  • 2.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(templates) ⇒ TemplateGraphAnalyzer

Initialize the analyzer with step templates

Parameters:

Since:

  • 2.2.0



34
35
36
37
38
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 34

def initialize(templates)
  @templates = templates
  @dependency_map = nil
  @analysis_cache = nil
end

Instance Attribute Details

#templatesArray<Tasker::Types::StepTemplate> (readonly)

Returns The step templates being analyzed.

Returns:

Since:

  • 2.2.0



29
30
31
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 29

def templates
  @templates
end

Instance Method Details

#analyzeHash

Perform comprehensive dependency analysis

Returns:

  • (Hash)

    Comprehensive dependency analysis containing:

    • :nodes - Array of step information with dependencies
    • :edges - Array of dependency relationships
    • :topology - Topologically sorted step names
    • :cycles - Array of detected circular dependencies
    • :levels - Hash mapping steps to their dependency depth levels
    • :roots - Array of steps with no dependencies
    • :leaves - Array of steps with no dependents
    • :summary - Summary statistics

Since:

  • 2.2.0



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 51

def analyze
  return @analysis_cache if @analysis_cache

  nodes = build_nodes
  edges = build_edges
  dependency_map = build_dependency_map
  cycles = detect_cycles(dependency_map)
  topology = cycles.empty? ? topological_sort(dependency_map) : []
  levels = calculate_dependency_levels(dependency_map, topology)
  roots = find_root_steps
  leaves = find_leaf_steps(edges)

  @analysis_cache = {
    nodes: nodes,
    edges: edges,
    topology: topology,
    cycles: cycles,
    levels: levels,
    roots: roots,
    leaves: leaves,
    summary: build_summary(cycles, levels, edges)
  }
end

#clear_cache!void

This method returns an undefined value.

Clear analysis cache (useful if templates change)

Since:

  • 2.2.0



120
121
122
123
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 120

def clear_cache!
  @analysis_cache = nil
  @dependency_map = nil
end

#cyclesArray<Array<String>>

Get detected circular dependencies

Returns:

  • (Array<Array<String>>)

    Array of detected cycles

Since:

  • 2.2.0



85
86
87
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 85

def cycles
  analyze[:cycles]
end

#has_cycles?Boolean

Check if the workflow has circular dependencies

Returns:

  • (Boolean)

    True if cycles are detected

Since:

  • 2.2.0



78
79
80
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 78

def has_cycles?
  cycles.any?
end

#leavesArray<String>

Get steps with no dependents (workflow exit points)

Returns:

  • (Array<String>)

    Leaf step names

Since:

  • 2.2.0



113
114
115
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 113

def leaves
  analyze[:leaves]
end

#levelsHash<String, Integer>

Get dependency levels for all steps

Returns:

  • (Hash<String, Integer>)

    Step name to dependency level mapping

Since:

  • 2.2.0



99
100
101
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 99

def levels
  analyze[:levels]
end

#rootsArray<String>

Get steps with no dependencies (workflow entry points)

Returns:

  • (Array<String>)

    Root step names

Since:

  • 2.2.0



106
107
108
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 106

def roots
  analyze[:roots]
end

#topologyArray<String>

Get topological ordering of steps

Returns:

  • (Array<String>)

    Topologically sorted step names

Since:

  • 2.2.0



92
93
94
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 92

def topology
  analyze[:topology]
end