Sha256: bf7e299a2cf55f8ae9d07d8dacf83f5a6d2c045531b77f73c96b1377ecb0e6ef

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

module Pallets
  module DSL
    module Workflow
      def task(arg=nil, as: nil, depends_on: nil, max_failures: nil, **kwargs)
        # Have to work more to keep Pallets' nice DSL valid in Ruby 2.7
        arg = !kwargs.empty? ? kwargs : arg
        raise ArgumentError, 'Task is incorrectly defined. It must receive '\
                             'either a name, or a name => dependencies pair as '\
                             'the first argument' unless arg

        klass, dependencies = case arg
        when Hash
          # The `task Foo => Bar` notation
          arg.first
        else
          # The `task Foo, depends_on: Bar` notation
          [arg, depends_on]
        end

        task_class = klass.to_s
        as ||= task_class

        dependencies = Array(dependencies).compact.uniq.map(&:to_s)
        graph.add(as, dependencies)

        task_config[as] = {
          'workflow_class' => self.name,
          'task_class' => task_class,
          'max_failures' => max_failures || Pallets.configuration.max_failures
        }

        nil
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pallets-0.11.0 lib/pallets/dsl/workflow.rb
pallets-0.10.0 lib/pallets/dsl/workflow.rb
pallets-0.9.0 lib/pallets/dsl/workflow.rb
pallets-0.8.0 lib/pallets/dsl/workflow.rb
pallets-0.7.0 lib/pallets/dsl/workflow.rb