Class: Abid::Task
- Inherits:
-
Rake::Task
- Object
- Rake::Task
- Abid::Task
- Extended by:
- Forwardable
- Defined in:
- lib/abid/task.rb
Instance Attribute Summary collapse
-
#extends ⇒ Object
Returns the value of attribute extends.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#play ⇒ Object
readonly
Returns the value of attribute play.
-
#play_class_definition ⇒ Object
Returns the value of attribute play_class_definition.
Class Method Summary collapse
-
.define_play(*args, &block) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #bind(**params) ⇒ Object
- #bind_play_hooks(tag, to = nil) ⇒ Object
- #bound? ⇒ Boolean
- #call_play_hooks(tag, *args) ⇒ Object
- #concerned? ⇒ Boolean
-
#execute(_args = nil) ⇒ Object
Execute the play associated with this task.
-
#initialize(task_name, app) ⇒ Task
constructor
A new instance of Task.
-
#name_with_args ⇒ Object
Name of task with argument list description.
-
#name_with_params ⇒ Object
Name of task with params.
- #needed? ⇒ Boolean
- #params_description ⇒ Object
- #play_class ⇒ Object
- #prerequisite_tasks ⇒ Object
Constructor Details
#initialize(task_name, app) ⇒ Task
Returns a new instance of Task.
10 11 12 13 |
# File 'lib/abid/task.rb', line 10 def initialize(task_name, app) super(task_name, app) @siblings = {} end |
Instance Attribute Details
#extends ⇒ Object
Returns the value of attribute extends.
5 6 7 |
# File 'lib/abid/task.rb', line 5 def extends @extends end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/abid/task.rb', line 6 def params @params end |
#play ⇒ Object (readonly)
Returns the value of attribute play.
6 7 8 |
# File 'lib/abid/task.rb', line 6 def play @play end |
#play_class_definition ⇒ Object
Returns the value of attribute play_class_definition.
5 6 7 |
# File 'lib/abid/task.rb', line 5 def play_class_definition @play_class_definition end |
Class Method Details
.define_play(*args, &block) ⇒ Object
:nodoc:
132 133 134 |
# File 'lib/abid/task.rb', line 132 def define_play(*args, &block) # :nodoc: Rake.application.define_play(self, *args, &block) end |
Instance Method Details
#bind(**params) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/abid/task.rb', line 30 def bind(**params) fail 'already bound' if bound? parsed_params = ParamsParser.parse(params, play_class.params_spec) return @siblings[parsed_params] if @siblings.include?(parsed_params) sorted_params = parsed_params.sort.to_h sorted_params.freeze @siblings[sorted_params] = dup.tap do |t| t.instance_eval do @prerequisites = [] @params = sorted_params @play = play_class.new(t) call_play_hooks(:setup) bind_play_hooks(:before, :before_execute) bind_play_hooks(:after, :after_invoke) end end end |
#bind_play_hooks(tag, to = nil) ⇒ Object
121 122 123 124 |
# File 'lib/abid/task.rb', line 121 def bind_play_hooks(tag, to = nil) to ||= tag hooks[to] = [proc { |*args| call_play_hooks(tag, *args) }] end |
#bound? ⇒ Boolean
26 27 28 |
# File 'lib/abid/task.rb', line 26 def bound? !@play.nil? end |
#call_play_hooks(tag, *args) ⇒ Object
126 127 128 129 |
# File 'lib/abid/task.rb', line 126 def call_play_hooks(tag, *args) return unless bound? play_class.hooks[tag].each { |blk| play.instance_exec(*args, &blk) } end |
#concerned? ⇒ Boolean
107 108 109 110 111 112 113 114 115 |
# File 'lib/abid/task.rb', line 107 def concerned? state.reload if !application..retry_failed_job && !application..repair && state.failed? && !top_level? fail "#{name} -- task has been failed" end application..repair || !state.successed? end |
#execute(_args = nil) ⇒ Object
Execute the play associated with this task.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/abid/task.rb', line 93 def execute(_args = nil) fail 'no play is bound yet' unless bound? if application..dryrun application.trace "** Execute (dry run) #{name_with_params}" return end if application..trace application.trace "** Execute #{name_with_params}" end play.run end |
#name_with_args ⇒ Object
Name of task with argument list description.
60 61 62 63 64 65 66 |
# File 'lib/abid/task.rb', line 60 def name_with_args # :nodoc: if params_description "#{super} #{params_description}" else super end end |
#name_with_params ⇒ Object
Name of task with params
69 70 71 72 73 74 75 |
# File 'lib/abid/task.rb', line 69 def name_with_params # :nodoc: if params_description "#{name} #{params_description}" else super end end |
#needed? ⇒ Boolean
117 118 119 |
# File 'lib/abid/task.rb', line 117 def needed? !state.successed? || prerequisite_tasks.any? { |t| t.session.successed? } end |
#params_description ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/abid/task.rb', line 77 def params_description sig_params = play_class.params_spec.select do |_, spec| spec[:significant] end return if sig_params.empty? if bound? # unbound p = sig_params.map { |name, _| "#{name}=#{params[name]}" } else p = sig_params.map { |name, spec| "#{name}:#{spec[:type]}" } end p.join(' ') end |
#play_class ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/abid/task.rb', line 15 def play_class return @play_class if @play_class task = self klass = application.lookup_play_class(extends, scope) @play_class = Class.new(klass) do |c| c.task = task c.class_eval(&task.play_class_definition) end end |
#prerequisite_tasks ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/abid/task.rb', line 51 def prerequisite_tasks fail 'no play is bound yet' unless bound? prerequisites.map do |pre, params| application[pre, @scope, **self.params.merge(params)] end end |