Sha256: 2406921bb2042dbcaea3ff57504aead36a29b0e360b8cd4f9f37150ac2a016f0

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 KB

Contents

module Eye::Patch

  class ProcessSet < Hash

    def initialize(group, processes)
      @group = group

      Array(processes).each do |process|
        parse_process(process)
      end
    end

    private

    def parse_process(process)
      if process[:count]
        parse_process_cluster(process)
      else
        parse_single_process(
          process[:name],
          process[:config],
          process_monitors(process))
      end
    end

    def parse_process_cluster(process)
      process[:count].times do |index|
        name = "#{process[:name]}-#{index}"
        parse_single_process(
          name,
          indexed_config(process[:config], index),
          process_monitors(process))
      end
    end

    def parse_single_process(name, config, monitors)
      self[name] = @group
        .merge(stdout: config[:stdall], stderr: config[:stdall])
        .merge(config)
        .merge(name: name, group: @group[:name])

      self[name][:triggers] = self[name][:triggers].merge(monitors[:triggers])
      self[name][:checks] = self[name][:checks].merge(monitors[:checks])
    end

    def indexed_config(config, index)
      config.each_with_object({}) do |(key, value), result|
        result[key] = value.is_a?(String) ? value.gsub("{ID}", index.to_s) : value
      end
    end

    def process_monitors(config)
      { triggers: OptionSet.new(Eye::Trigger, config[:triggers]),
        checks: OptionSet.new(Eye::Checker, config[:checks]) }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eye-patch-0.4.0 lib/eye/patch/process_set.rb
eye-patch-0.3.1 lib/eye/patch/process_set.rb
eye-patch-0.3.0 lib/eye/patch/process_set.rb
eye-patch-0.2.2 lib/eye/patch/process_set.rb
eye-patch-0.2.1 lib/eye/patch/process_set.rb
eye-patch-0.2.0 lib/eye/patch/process_set.rb
eye-patch-0.1.8 lib/eye/patch/process_set.rb
eye-patch-0.1.7 lib/eye/patch/process_set.rb
eye-patch-0.1.6 lib/eye/patch/process_set.rb
eye-patch-0.1.5 lib/eye/patch/process_set.rb