Class: Eco::API::Session::Batch::Feedback
- Inherits:
-
Object
- Object
- Eco::API::Session::Batch::Feedback
- Defined in:
- lib/eco/api/session/batch/feedback.rb
Instance Attribute Summary collapse
-
#job ⇒ Eco::API::Session::Batch::Job
readonly
batch jobthe feedback is associated with.
Instance Method Summary collapse
-
#as_update(entry) ⇒ Object
Slightly modifies the behaviour of
Ecoportal::API::Common::BaseModel#as_update, so schema details fields show thealt_id. -
#generate(requests = nil, max_chars: 800, only_stats: false) ⇒ String
Generates the lines of feedback of the current requests.
-
#initialize(job:) ⇒ Feedback
constructor
A new instance of Feedback.
- #job_requests ⇒ Object
-
#name ⇒ String
Name of the
batch job. - #options ⇒ Object
-
#request_stats(requests = nil) ⇒ Eco::API::Session::Batch::RequestStats
The stats object of the current requests.
- #sets ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(job:) ⇒ Feedback
Returns a new instance of Feedback.
11 12 13 14 |
# File 'lib/eco/api/session/batch/feedback.rb', line 11 def initialize(job:) raise "A Eco::API::Session::Batch::Job object is required. Given: #{job}" unless job.is_a?(Eco::API::Session::Batch::Job) @job = job end |
Instance Attribute Details
#job ⇒ Eco::API::Session::Batch::Job (readonly)
batch job the feedback is associated with
6 7 8 |
# File 'lib/eco/api/session/batch/feedback.rb', line 6 def job @job end |
Instance Method Details
#as_update(entry) ⇒ Object
for better feedback
Slightly modifies the behaviour of Ecoportal::API::Common::BaseModel#as_update, so schema details fields show the alt_id
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/eco/api/session/batch/feedback.rb', line 45 def as_update(entry) case when entry.is_a?(Hash) hash = entry else #entry.is_a?(Ecoportal::API::V1::Person) if only_ids? hash = { "id" => entry.id, "external_id" => entry.external_id, "email" => entry.email } hash = entry.as_json.slice("id", "external_id", "email") else hash = entry.as_update #if entry.details if hash["details"] if hfields = hash.dig("details", "fields") hfields.each do |fld| fld.merge!("alt_id" => entry.details.get_field(fld["id"]).alt_id) end end end if account = hash["account"] if account.keys == ["send_invites"] && !account["send_invites"] hash.delete("account") hash.delete("id") if hash.keys == ["id"] end end end end hash || {} end |
#generate(requests = nil, max_chars: 800, only_stats: false) ⇒ String
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
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/eco/api/session/batch/feedback.rb', line 94 def generate(requests = nil, max_chars: 800, only_stats: false) 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 > 0 request end msg << "#{sample.slice(0, sample_length).pretty_inspect}" end stats_str = "#{"+"*3} #{type.to_s.upcase} length: #{requests.length} #{"+"*3} STATS (job '#{name}') #{"+"*3}" msg << "#{"-"*stats_str.length}" if only_stats msg << stats_str msg << "#{request_stats(requests).message}" msg << "#{"-"*stats_str.length}" if only_stats msg << "*" * header.length unless only_stats end end.join("\n") end |
#job_requests ⇒ Object
38 39 40 |
# File 'lib/eco/api/session/batch/feedback.rb', line 38 def job_requests job.requests end |
#name ⇒ String
Returns name of the batch job.
18 19 20 |
# File 'lib/eco/api/session/batch/feedback.rb', line 18 def name job.name end |
#options ⇒ Object
33 34 35 |
# File 'lib/eco/api/session/batch/feedback.rb', line 33 def job. end |
#request_stats(requests = nil) ⇒ Eco::API::Session::Batch::RequestStats
if requests is not provided, it uses the last requests of the parent Batch::Job job
Returns the stats object of the current requests.
82 83 84 85 86 |
# File 'lib/eco/api/session/batch/feedback.rb', line 82 def request_stats(requests = nil) requests ||= job.requests return @request_stats if @request_stats && requests == job.requests @request_stats ||= Eco::API::Session::Batch::RequestStats.new(type: type, requests: requests) end |
#sets ⇒ Object
28 29 30 |
# File 'lib/eco/api/session/batch/feedback.rb', line 28 def sets job.sets end |
#type ⇒ Object
23 24 25 |
# File 'lib/eco/api/session/batch/feedback.rb', line 23 def type job.type end |