Class: RubyReactor::Map::ResultSummary

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_reactor/map/result_summary.rb

Overview

A map's result set is unbounded, so the API describes it instead of inlining it. Inlining meant the JSON encoder materialized the lazy ResultEnumerator itself — one storage read per element — and rendered every element failure as an opaque blob with no count of how many there were.

Constant Summary collapse

SAMPLE_LIMIT =

How many failed elements are described in full. The rest are only counted — a map failing 50k elements must not produce a 50k-entry response.

25
BACKTRACE_FRAMES =

Sampled failures are a list, not a detail view, and the same summary is echoed in intermediate_results, the execution trace and the undo stack — full traces on each would triple a large payload.

10

Class Method Summary collapse

Class Method Details

.build(enumerator) ⇒ Object

ponytail: one windowed read of the whole map; paginate if maps grow past what fits in a single response.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_reactor/map/result_summary.rb', line 22

def self.build(enumerator)
  total = enumerator.count
  results = RubyReactor.configuration.storage_adapter.retrieve_map_results_batch(
    enumerator.map_id, enumerator.reactor_class_name, offset: 0, limit: total
  )
  # Slots are index-keyed and the window starts at 0, so a full read means
  # position == element index. A short read means the map is still filling
  # in and gaps would shift positions — then indices are omitted.
  failures = collect_failures(results, indexed: results.size == total)

  {
    "_type" => "map_results",
    "total" => total,
    "succeeded" => total - failures[:count],
    "failed" => failures[:count],
    "failures" => failures[:sample],
    "failures_truncated" => failures[:count] > failures[:sample].size
  }
end