lib/tap/workflow.rb in bahuvrihi-tap-0.10.2 vs lib/tap/workflow.rb in bahuvrihi-tap-0.10.3
- old
+ new
@@ -74,47 +74,21 @@
#
# w1.enq(0)
# app.run
# app.results(w1.exit_points, w2.exit_points)) # => [8, -8]
#
- class Workflow
- include Support::Framework
-
- class << self
- protected
-
- def define(name, klass=Tap::Task, &block)
- instance_var = "@#{name}".to_sym
-
- define_method(name) do |*args|
- raise ArgumentError, "wrong number of arguments (#{args.length} for 1)" if args.length > 1
-
- instance_name = args[0] || name
- instance_variable_set(instance_var, {}) unless instance_variable_defined?(instance_var)
- instance_variable_get(instance_var)[instance_name] ||= task(instance_name, klass, &block)
- end
-
- define_method("#{name}=") do |input|
- input = {name => input} unless input.kind_of?(Hash)
- instance_variable_set(instance_var, input)
- end
- end
- end
+ class Workflow < Task
# The entry point for self.
attr_accessor :entry_point
# The exit point for self.
attr_accessor :exit_point
-
- # The task block provided during initialization.
- attr_reader :task_block
-
+
# Creates a new Task with the specified attributes.
def initialize(config={}, name=nil, app=App.instance, &task_block)
- super(config, name, app)
- @task_block = (task_block == nil ? default_task_block : task_block)
+ super
initialize_workflow
end
# Initializes a new batch object, running workflow to set the
# instance-specific entry/exit points. Raises an error if
@@ -155,46 +129,33 @@
# Enqueues all entry points for self and self.batch to app
# with the inputs. The number of inputs provided should match
# the number of inputs required by all the entry points;
# if the entry points have different input requirements, they
# have to be enqued separately.
- def enq(*inputs)
+ def unbatched_enq(*inputs)
entry_points.each do |task|
app.enq(task, *inputs)
end
end
-
- batch_function :enq
-
+
# Sets the on_complete_block for all exit points for self and
# self.batch. Use unbatched_on_complete to set the on_complete_block
# for just self.exit_points.
- def on_complete(override=false, &block)
+ def unbatched_on_complete(override=false, &block)
exit_points.each do |task|
task.on_complete(override, &block)
end
self
end
-
- batch_function(:on_complete) {}
-
- def task(name, klass=Tap::Task, &block)
- configs = config[name] || {}
- raise ArgumentError, "config '#{name}' is not a hash" unless configs.kind_of?(Hash)
- klass.new(configs, name, &block)
- end
-
+
# The workflow definition method. By default workflow
# simply calls the task_block. In subclasses, workflow
# should be overridden to provide the workflow definition.
def workflow
task_block.call(self) if task_block
end
- protected
-
- # Hook to set a default task block. By default, nil.
- def default_task_block
- nil
+ def process(*inputs)
+ enq(*inputs)
end
end
end
\ No newline at end of file