Method: Cts::Mpx::Aci::Tasks::Collect#collect

Defined in:
lib/cts/mpx/aci/tasks/collect.rb

#collectObject

Executes the array of queries one by one. Collecting the result into the collections attribute.

Raises:

  • (RuntimeError)

    when queries is not set correctly

  • (ArgumentError)

    when the user attribute is not set

  • (ArgumentError)

    when the account_id attribute is not set

  • (ArgumentError)

    when a query does not have service set

  • (ArgumentError)

    when a query does not have endpoint set



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cts/mpx/aci/tasks/collect.rb', line 20

def collect
  raise "empty queries array" if @queries&.empty?
  raise 'must set the queries attribute.' unless queries

  @entries = Entries.new

  queries.each do |config|
    query = run_query(config)

    if query&.entries.count.positive?
      log_collected_zero_entries config
      next
    end

    @entries += query.page.to_mpx_entries
    @entries.each do |entry|
      # if we collect the read only fields, it just messes everything up.
      # best to just not collect them.
      service_read_only_fields.each { |field| entry.fields.remove field }

      log_collected entry
    end
  end
end