Class: Greenroom::Census::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/greenroom/census/run.rb

Overview

Does the work of one row: freeze it, count it, tell the recorder which row is being looked at, then call the host's target through the reader. Kept as a single, small method so a census job's each_iteration (see Census::Job) is just @run.visit(row).

Instance Method Summary collapse

Constructor Details

#initialize(target:, recorder:, reader:) ⇒ Run

Returns a new instance of Run.



24
25
26
27
28
# File 'lib/greenroom/census/run.rb', line 24

def initialize(target:, recorder:, reader:)
  @target = target
  @recorder = recorder
  @reader = reader
end

Instance Method Details

#visit(row) ⇒ Object

The control and candidate blocks run on the same row object, and Scientist shuffles their execution order; without freezing, a candidate's write would look like a mismatch caused by the control (or vice versa) rather than what it is, a bug in that one row's candidate.

A raising row is caught here rather than left to escape: one bad row must not stop the rest of the census, and record_row_error keeps the count of rows that never reached a comparison visible instead of silently inflating rows_scanned beyond what was actually examined. StandardError, not Exception, so a signal like SystemExit still propagates; Census::Middleware is this gem's backstop for a row that escapes some other way.



43
44
45
46
47
48
49
50
# File 'lib/greenroom/census/run.rb', line 43

def visit(row)
  row.freeze
  @recorder.count_row
  @recorder.subject = subject_for(row)
  @reader.call { @target.call(row) }
rescue => e
  @recorder.record_row_error(e)
end