Module: Pwrake::TaskAlgorithm
- Included in:
- Rake::Task
- Defined in:
- lib/pwrake/task/task_algorithm.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#property ⇒ Object
readonly
Returns the value of attribute property.
-
#subsequents ⇒ Object
readonly
Returns the value of attribute subsequents.
-
#unfinished_prereq ⇒ Object
readonly
Returns the value of attribute unfinished_prereq.
Instance Method Summary collapse
- #check_prereq_finished(preq_name = nil) ⇒ Object
- #pw_enq_subsequents ⇒ Object
- #pw_search_tasks(args) ⇒ Object
- #pw_set_property(property) ⇒ Object
-
#search_prerequisites(task_args, invocation_chain) ⇒ Object
Search all the prerequisites of a task.
-
#search_with_call_chain(subseq, task_args, invocation_chain) ⇒ Object
Same as search, but explicitly pass a call chain to detect circular dependencies.
- #wrapper ⇒ Object
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
9 10 11 |
# File 'lib/pwrake/task/task_algorithm.rb', line 9 def arguments @arguments end |
#property ⇒ Object (readonly)
Returns the value of attribute property.
10 11 12 |
# File 'lib/pwrake/task/task_algorithm.rb', line 10 def property @property end |
#subsequents ⇒ Object (readonly)
Returns the value of attribute subsequents.
8 9 10 |
# File 'lib/pwrake/task/task_algorithm.rb', line 8 def subsequents @subsequents end |
#unfinished_prereq ⇒ Object (readonly)
Returns the value of attribute unfinished_prereq.
11 12 13 |
# File 'lib/pwrake/task/task_algorithm.rb', line 11 def unfinished_prereq @unfinished_prereq end |
Instance Method Details
#check_prereq_finished(preq_name = nil) ⇒ Object
97 98 99 100 |
# File 'lib/pwrake/task/task_algorithm.rb', line 97 def check_prereq_finished(preq_name=nil) @unfinished_prereq.delete(preq_name) !@already_finished && @unfinished_prereq.empty? end |
#pw_enq_subsequents ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/pwrake/task/task_algorithm.rb', line 87 def pw_enq_subsequents # not synchronize owing to fiber @subsequents.each do |t| # <<--- competition !!! if t && t.check_prereq_finished(self.name) application.task_queue.enq(t.wrapper) end end @already_finished = true # <<--- competition !!! end |
#pw_search_tasks(args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pwrake/task/task_algorithm.rb', line 21 def pw_search_tasks(args) Log.debug "#{self.class}[#{name}]#pw_search_tasks start, args=#{args.inspect}" if application..trace application.trace "** Search #{name}#{format_search_flags}" end cl = Pwrake.clock TaskWrapper.clear_rank task_args = TaskArguments.new(arg_names, args) # not synchronize owing to fiber search_with_call_chain(nil, task_args, InvocationChain::EMPTY) # Log.debug "#{self.class}[#{name}]#pw_search_tasks end t=%.6f" % (Pwrake.clock-cl) end |
#pw_set_property(property) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/pwrake/task/task_algorithm.rb', line 102 def pw_set_property(property) if @property @property.merge(property) else @property = property end self end |
#search_prerequisites(task_args, invocation_chain) ⇒ Object
Search all the prerequisites of a task.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pwrake/task/task_algorithm.rb', line 66 def search_prerequisites(task_args, invocation_chain) # :nodoc: @unfinished_prereq = {} @prerequisites.each{|t| @unfinished_prereq[t]=true} prerequisite_tasks.each { |prereq| prereq_args = task_args.new_scope(prereq.arg_names) if prereq.search_with_call_chain(self, prereq_args, invocation_chain) @unfinished_prereq.delete(prereq.name) end } end |
#search_with_call_chain(subseq, task_args, invocation_chain) ⇒ Object
Same as search, but explicitly pass a call chain to detect circular dependencies.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pwrake/task/task_algorithm.rb', line 37 def search_with_call_chain(subseq, task_args, invocation_chain) # :nodoc: new_chain = InvocationChain.append(self, invocation_chain) @lock.synchronize do return true if @already_finished # <<--- competition !!! @subsequents ||= [] @subsequents << subseq if subseq # <<--- competition !!! if ! @already_searched @already_searched = true @arguments = task_args @wrapper = TaskWrapper.new(self,task_args) if @prerequisites.empty? @unfinished_prereq = {} else search_prerequisites(task_args, new_chain) end #check_and_enq if !@already_finished && @unfinished_prereq.empty? application.task_queue.enq(@wrapper) end end return false end rescue Exception => ex add_chain_to(ex, new_chain) raise ex end |
#wrapper ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/pwrake/task/task_algorithm.rb', line 13 def wrapper if @wrapper.nil? Log.debug "TaskWrapper is not defined for #{self.class}[#{name}]" @wrapper = TaskWrapper.new(self) end @wrapper end |