Module: Asgard::Base::DependencyGraph
- Included in:
- Asgard::Base
- Defined in:
- lib/asgard/base/dependency_graph.rb
Overview
Dependency declaration (depends_on) and full-graph validation
(validate_deps!), backed by stdlib TSort for cycle detection.
Instance Method Summary collapse
- #_deps ⇒ Object
-
#depends_on(*tasks) ⇒ Object
Declare dependencies for the next task.
-
#validate_deps! ⇒ Object
Validate the full dep graph for cycles using stdlib TSort.
Instance Method Details
#_deps ⇒ Object
8 9 10 |
# File 'lib/asgard/base/dependency_graph.rb', line 8 def _deps @_deps ||= {} end |
#depends_on(*tasks) ⇒ Object
Declare dependencies for the next task. Bare symbols run sequentially; arrays within the splat run in parallel.
depends_on :build # sequential
depends_on :build, :lint # both sequential
depends_on [:build, :lint] # build and lint in parallel
depends_on :setup, [:build, :lint], :test # setup, then build+lint, then test
A sole Proc/lambda defers resolution to validate_deps! (after every .loki file has loaded), instead of now. It must return the same shape the splat form above would: an array of stages, each a Symbol (sequential) or Array (parallel group).
depends_on -> { [all_commands.keys.grep(/_check\z/).map(&:to_sym)] }
26 27 28 |
# File 'lib/asgard/base/dependency_graph.rb', line 26 def depends_on(*tasks) @_pending_deps = tasks end |
#validate_deps! ⇒ Object
Validate the full dep graph for cycles using stdlib TSort.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/asgard/base/dependency_graph.rb', line 31 def validate_deps! _check_orphaned_deps! return if _deps.empty? _resolve_lazy_deps! all_task_names = all_commands.keys.map(&:to_sym) _check_undefined_deps!(all_task_names) _check_dep_arities! _build_and_sort_graph(all_task_names) rescue TSort::Cyclic => e raise Asgard::CircularDependencyError, e. end |