Sha256: cf3c1918d06bdd45a7e57c1dfe639d893f336c82c1cf82e750c726745c5bb1cc

Contents?: true

Size: 1017 Bytes

Versions: 5

Compression:

Stored size: 1017 Bytes

Contents

require 'rundock'

module Rundock
  class Node
    attr_reader :name
    attr_reader :operations
    attr_reader :backend
    attr_accessor :hooks

    def initialize(name, backend)
      @name = name
      @backend = backend
      @operations = []
      @hooks = []
    end

    def add_operation(ope)
      @operations = [] unless @operations
      @operations << ope
    end

    def run
      Logger.formatter.onrec = true
      Logger.debug("run node: #{@name}")
      Logger.warn("no operation running: #{@name}") if @operations.blank?

      nodeinfo = nil

      @operations.each do |ope|
        Logger.debug("run operation: #{ope.class}")
        nodeinfo = ope.attributes[:nodeinfo] if nodeinfo.nil?
        ope.run(@backend, ope.attributes)
      end

      log_buffer = Logger.formatter.flush unless Logger.formatter.buffer.empty?

      @hooks.each do |h|
        Logger.debug("run hook: #{h.name}")
        h.hook(log_buffer, nodeinfo)
      end

      Logger.formatter.onrec = false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rundock-0.4.8 lib/rundock/node.rb
rundock-0.4.7 lib/rundock/node.rb
rundock-0.4.6 lib/rundock/node.rb
rundock-0.4.4 lib/rundock/node.rb
rundock-0.4.3 lib/rundock/node.rb