Sha256: a803f319011ca3010768d9b53adc158d2c3c7ba1a2a29f105d2ce36f91830ea0

Contents?: true

Size: 1.7 KB

Versions: 37

Compression:

Stored size: 1.7 KB

Contents

require 'dply/logger'
module Dplyr
  class Report

    include ::Dply::Logger
    attr_reader :hosts, :exit_statuses 

    def initialize(hosts, exit_statuses, messages)
      @hosts = hosts
      @exit_statuses = exit_statuses
      @messages = messages
    end


    def print_full
      logger.marker "summary_start"
      print_successful_jobs
      print_failed_jobs
      print_summary
    end

    def succeeded
      @succeeded ||= exit_statuses.keys.select do |k|
        exit_statuses[k] == 0
      end
    end

    def failed
      @failed ||= exit_statuses.keys.select do |k|
        exit_statuses[k] != 0
      end
    end

    def print_successful_jobs
      puts "succeeded".green
      succeeded.each do |host|
        messages = @messages[host] 
        puts " - #{host[:id]}:"
        next if not messages.is_a? Array
        messages.each { |m| puts "   #{m}"}
      end
    end

    def print_failed_jobs
      return if failed.count == 0
      puts "failed".red
      failed.each do |host|
        puts " - #{host[:id]}"
      end
    end


    def print_summary
      total_hosts = hosts.count
      run_count = @exit_statuses.count
      not_run = total_hosts - run_count
      if (failed.count > 0 || not_run > 0 )
        not_run_error = "not run on #{not_run} of #{total_hosts} hosts" if not_run > 0
        failed_error = "failed on #{failed.count} of #{total_hosts} hosts" if failed.count > 0
       
        errors = []
        errors << not_run_error if not_run_error
        errors << failed_error if failed_error

        error_str = "task #{errors.join(", ")}"
        raise ::Dply::Error, error_str
      end
      puts "tasks ran successfully on #{succeeded.count}/#{total_hosts} hosts"
    end

  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
dply-0.3.15 lib/dplyr/report.rb
dply-0.3.14 lib/dplyr/report.rb
dply-0.3.13 lib/dplyr/report.rb
dply-0.3.12 lib/dplyr/report.rb
dply-0.3.11 lib/dplyr/report.rb
dply-0.3.10 lib/dplyr/report.rb
dply-0.3.9 lib/dplyr/report.rb
dply-0.3.8 lib/dplyr/report.rb
dply-0.3.7 lib/dplyr/report.rb
dply-0.3.6 lib/dplyr/report.rb
dply-0.3.5 lib/dplyr/report.rb
dply-0.3.4 lib/dplyr/report.rb
dply-0.3.3 lib/dplyr/report.rb
dply-0.3.2 lib/dplyr/report.rb
dply-0.3.1 lib/dplyr/report.rb
dply-0.3.0 lib/dplyr/report.rb
dply-0.2.19 lib/dplyr/report.rb
dply-0.2.18 lib/dplyr/report.rb
dply-0.2.17 lib/dplyr/report.rb
dply-0.2.16 lib/dplyr/report.rb