Module: Eco::API::Session::Batch::Feedback::Generate

Includes:
JobDependencies, RequestStat
Included in:
Eco::API::Session::Batch::Feedback
Defined in:
lib/eco/api/session/batch/feedback/generate.rb

Pure feedback methods collapse

Methods included from RequestStat

#request_stats

Methods included from JobDependencies

#job, #job_requests, #name, #options, #sets, #type

Instance Method Details

#generate(requests = nil, max_chars: 800, only_stats: false) ⇒ String

Note:

if requests is not provided, it uses the last requests of the parent Batch::Job job

Generates the lines of feedback of the current requests

Parameters:

  • requests (Enumerable<Hash>) (defaults to: nil)

    raw requests as they would be sent to the Server

  • max_chars (Integer) (defaults to: 800)

    the max number of characters for the current feedback message

  • only_stats (Boolean) (defaults to: false)

    whether or not should only include a brief summary of stats

Returns:

  • (String)

    the feedback message



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/eco/api/session/batch/feedback/generate.rb', line 18

def generate(requests = nil, max_chars: 800, only_stats: false) # rubocop:disable Metrics/AbcSize
  requests ||= job_requests

  [].tap do |msg|
    if !requests || !requests.is_a?(Enumerable) || requests.empty?
      msg << "#{'*' * 10} Nothing for #{signature} so far :)  #{'*' * 10}"
    else
      header = "#{'*' * 10}  #{signature} - Feedback Sample #{'*' * 10}"
      msg << header unless only_stats

      unless only_stats
        sample_length = 1
        sample = requests.slice(0, 20).map do |request|
          max_chars     -= request.pretty_inspect.length
          sample_length += 1 if max_chars.positive?
          request
        end

        msg << sample.slice(0, sample_length).pretty_inspect
      end

      stats_str  = "#{'+' * 3}   "
      stats_str << "#{type.to_s.upcase} length: #{requests.length} "
      stats_str << "#{'+' * 3}  "
      stats_str << "STATS  (job '#{name}')  "
      stats_str << ('+' * 3)

      msg << ('-' * stats_str.length) if only_stats
      msg << stats_str
      msg << request_stats(requests).message.to_s
      msg << ('-' * stats_str.length) if only_stats
      msg << ('*' * header.length)    unless only_stats
    end
  end.join("\n")
end