Module: Asgard::Base::Dispatch
- Included in:
- Asgard::Base
- Defined in:
- lib/asgard/base/dispatch.rb
Overview
Task execution engine: resolves and runs declared dependencies (in parallel where declared) before the target command runs.
Completion-based deduplication: a task is only marked done after its body finishes. Threads that arrive at an already-running shared dep wait on its ConditionVariable rather than proceeding immediately, preventing the race where parallel tasks start before a shared dep has actually completed.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #dep_result(task) ⇒ Object
-
#dep_results ⇒ Object
The results of +target+'s direct dependencies, keyed by task name — available to a task body while it runs, e.g.
-
#invoke_command(command) ⇒ Object
Dispatch hook: resolves and runs all deps (in parallel where declared) before executing the target command.
Class Method Details
.included(base) ⇒ Object
14 15 16 |
# File 'lib/asgard/base/dispatch.rb', line 14 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#dep_result(task) ⇒ Object
77 78 79 |
# File 'lib/asgard/base/dispatch.rb', line 77 def dep_result(task) dep_results[task.to_sym] end |
#dep_results ⇒ Object
The results of +target+'s direct dependencies, keyed by task name —
available to a task body while it runs, e.g. dep_result(:test_check).
73 74 75 |
# File 'lib/asgard/base/dispatch.rb', line 73 def dep_results Thread.current[:asgard_dep_results] || {} end |
#invoke_command(command) ⇒ Object
Dispatch hook: resolves and runs all deps (in parallel where declared) before executing the target command.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/asgard/base/dispatch.rb', line 55 def invoke_command(command, *) $DEBUG = true if [:debug] $VERBOSE = true if [:verbose] target = command.name.to_sym return cached_result(target) unless acquire_run_token(target) result = nil begin resolved_deps = run_deps_for(target) result = with_dep_results(resolved_deps) { command.run(self, *) } ensure signal_done(target, result) end result end |