Class: Swineherd::Workflow
- Inherits:
-
Object
- Object
- Swineherd::Workflow
- Defined in:
- lib/swineherd/workflow.rb
Instance Attribute Summary collapse
-
#output_counts ⇒ Object
Returns the value of attribute output_counts.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
-
#workdir ⇒ Object
Returns the value of attribute workdir.
Instance Method Summary collapse
-
#describe ⇒ Object
Describes the dependency tree of all tasks belonging to self.
-
#initialize(flow_id, &blk) ⇒ Workflow
constructor
Create a new workflow and new namespace for this workflow.
-
#latest_output(taskname) ⇒ Object
Get latest output of taskname.
-
#next_output(taskname) ⇒ Object
Get next logical output of taskname by incrementing internal counter.
-
#run(taskname) ⇒ Object
Runs workflow starting with taskname.
Constructor Details
#initialize(flow_id, &blk) ⇒ Workflow
Create a new workflow and new namespace for this workflow
8 9 10 11 12 13 14 15 |
# File 'lib/swineherd/workflow.rb', line 8 def initialize flow_id, &blk @flow_id = flow_id @output_counts = Hash.new{|h,k| h[k] = 0} @outputs = Hash.new{|h,k| h[k] = []} namespace @flow_id do self.instance_eval(&blk) end end |
Instance Attribute Details
#output_counts ⇒ Object
Returns the value of attribute output_counts.
3 4 5 |
# File 'lib/swineherd/workflow.rb', line 3 def output_counts @output_counts end |
#outputs ⇒ Object
Returns the value of attribute outputs.
3 4 5 |
# File 'lib/swineherd/workflow.rb', line 3 def outputs @outputs end |
#workdir ⇒ Object
Returns the value of attribute workdir.
3 4 5 |
# File 'lib/swineherd/workflow.rb', line 3 def workdir @workdir end |
Instance Method Details
#describe ⇒ Object
Describes the dependency tree of all tasks belonging to self
46 47 48 49 50 |
# File 'lib/swineherd/workflow.rb', line 46 def describe Rake::Task.tasks.each do |t| Log.info("Task: #{t.name} [#{t.inspect}]") if t.name =~ /#{@flow_id}/ end end |
#latest_output(taskname) ⇒ Object
Get latest output of taskname
30 31 32 |
# File 'lib/swineherd/workflow.rb', line 30 def latest_output taskname @outputs[taskname].last end |
#next_output(taskname) ⇒ Object
Get next logical output of taskname by incrementing internal counter
20 21 22 23 24 25 |
# File 'lib/swineherd/workflow.rb', line 20 def next_output taskname raise "No working directory specified." unless @workdir @outputs[taskname] << "#{@workdir}/#{@flow_id}/#{taskname}-#{@output_counts[taskname]}" @output_counts[taskname] += 1 latest_output(taskname) end |
#run(taskname) ⇒ Object
Runs workflow starting with taskname
37 38 39 40 41 |
# File 'lib/swineherd/workflow.rb', line 37 def run taskname Log.info "Launching workflow task #{@flow_id}:#{taskname} ..." Rake::Task["#{@flow_id}:#{taskname}"].invoke Log.info "Workflow task #{@flow_id}:#{taskname} finished" end |