Sha256: 164b73e525c057a06ebff5f6efd1d03c70bed8388cac9f9bd844e53e8e9aa378

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

module Orchestra
  class Operation < Module
    def self.new *args, &block
      return super unless block_given?
      unless args.empty?
        raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
      end
      builder = DSL::Operations::Builder.new
      DSL::Operations::Context.evaluate builder, &block
      builder.build_operation
    end

    extend Forwardable

    def_delegators :@default_run_list, :node_names, :provisions, :dependencies,
      :optional_dependencies, :required_dependencies

    attr :registry, :result, :nodes

    def initialize args = {}
      @result, @command, @nodes = Util.extract_key_args args,
        :result, :command => false, :nodes => {}
      @default_run_list = RunList.build nodes, result, []
    end

    def process output
      output.select do |key, _| key = result end
    end

    def start_performance *args
      conductor, input = extract_args args
      run_list = RunList.build nodes, result, input.keys
      performance = Performance.new conductor, run_list, input
      yield performance if block_given?
      performance.publish :operation_entered, name, input
      performance
    end

    def perform *args, &block
      performance = start_performance *args, &block
      performance.perform
      output = performance.extract_result result
      performance.publish :operation_exited, name, output
      @command ? nil : output
    end

    def command?
      @command ? true : false
    end

    private

    def extract_args args
      conductor = args.size > 1 ? args.shift : Conductor.new
      input = args.fetch 0 do {} end
      [conductor, input]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ntl-orchestra-0.9.2 lib/orchestra/operation.rb
ntl-orchestra-0.9.1 lib/orchestra/operation.rb