Class: Fractor::Workflow::DependencyResolver
- Inherits:
-
Object
- Object
- Fractor::Workflow::DependencyResolver
- Defined in:
- lib/fractor/workflow/execution/dependency_resolver.rb
Overview
Computes the execution order for workflow jobs using topological sort. Jobs are grouped into levels where all jobs in a level can be executed in parallel (their dependencies are satisfied).
Caches execution order based on job structure to avoid recomputing topological sort for static workflow definitions.
Class Attribute Summary collapse
-
.cache ⇒ Object
readonly
Returns the value of attribute cache.
Class Method Summary collapse
-
.clear_cache ⇒ Object
Clear the entire execution order cache.
-
.clear_cache_for(workflow_signature) ⇒ Object
Clear cache entries for a specific workflow.
Instance Method Summary collapse
-
#execution_order ⇒ Array<Array<String>>
Compute the execution order using topological sort.
-
#initialize(jobs, enable_cache: true) ⇒ DependencyResolver
constructor
Initialize the resolver with a workflow's jobs.
-
#invalidate_cache ⇒ Object
Invalidate the cache for this workflow's execution order.
Constructor Details
#initialize(jobs, enable_cache: true) ⇒ DependencyResolver
Initialize the resolver with a workflow's jobs.
41 42 43 44 45 |
# File 'lib/fractor/workflow/execution/dependency_resolver.rb', line 41 def initialize(jobs, enable_cache: true) @jobs = jobs @enable_cache = enable_cache @signature = compute_signature if enable_cache end |
Class Attribute Details
.cache ⇒ Object (readonly)
Returns the value of attribute cache.
21 22 23 |
# File 'lib/fractor/workflow/execution/dependency_resolver.rb', line 21 def cache @cache end |
Class Method Details
.clear_cache ⇒ Object
Clear the entire execution order cache. Useful for testing or when workflows are dynamically modified.
25 26 27 |
# File 'lib/fractor/workflow/execution/dependency_resolver.rb', line 25 def clear_cache @mutex.synchronize { @cache.clear } end |
.clear_cache_for(workflow_signature) ⇒ Object
Clear cache entries for a specific workflow.
32 33 34 |
# File 'lib/fractor/workflow/execution/dependency_resolver.rb', line 32 def clear_cache_for(workflow_signature) @mutex.synchronize { @cache.delete(workflow_signature) } end |
Instance Method Details
#execution_order ⇒ Array<Array<String>>
Compute the execution order using topological sort. Returns an array of arrays, where each inner array contains job names that can be executed in parallel (their dependencies are satisfied).
Results are cached based on the workflow's job structure (job names and their dependencies). This provides significant performance benefits for workflows that are executed multiple times.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fractor/workflow/execution/dependency_resolver.rb', line 56 def execution_order # Try to get from cache first if @enable_cache && @signature && cached_execution_order return cached_execution_order end # Compute the execution order order = compute_order # Cache the result cache_execution_order(order) if @enable_cache && @signature order end |
#invalidate_cache ⇒ Object
Invalidate the cache for this workflow's execution order. Call this if the workflow definition changes dynamically.
73 74 75 76 77 78 |
# File 'lib/fractor/workflow/execution/dependency_resolver.rb', line 73 def invalidate_cache return unless @enable_cache && @signature self.class.clear_cache_for(@signature) @cached = false end |