Class: Karafka::Web::Processing::Consumers::Aggregators::State::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/processing/consumers/aggregators/state/context.rb

Overview

Shared, per-call value object passed through the State pipeline steps.

Each step reads and mutates the contents of state/active_reports in place to enrich the materialized state for the next step, instead of each step reaching into State's own ivars directly. This keeps steps isolated and independently testable with a hand-built Context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state:, active_reports:, aggregated_from:, report:, offset:) ⇒ Context

Initialize all instance variables upfront so every instance has the same object shape, avoiding Ruby's :performance "shape variations" warning.

Parameters:

  • state (Hash)

    current materialized state (mutated in place by steps)

  • active_reports (Hash)

    process reports memoized by the aggregator

  • aggregated_from (Float)

    time from which this aggregation run comes

  • report (Hash)

    the incoming consumer process state report

  • offset (Integer)

    offset of the message with the state report



24
25
26
27
28
29
30
# File 'lib/karafka/web/processing/consumers/aggregators/state/context.rb', line 24

def initialize(state:, active_reports:, aggregated_from:, report:, offset:)
  @state = state
  @active_reports = active_reports
  @aggregated_from = aggregated_from
  @report = report
  @offset = offset
end

Instance Attribute Details

#active_reportsObject (readonly)

Returns the value of attribute active_reports.



32
33
34
# File 'lib/karafka/web/processing/consumers/aggregators/state/context.rb', line 32

def active_reports
  @active_reports
end

#aggregated_fromObject (readonly)

Returns the value of attribute aggregated_from.



32
33
34
# File 'lib/karafka/web/processing/consumers/aggregators/state/context.rb', line 32

def aggregated_from
  @aggregated_from
end

#offsetObject (readonly)

Returns the value of attribute offset.



32
33
34
# File 'lib/karafka/web/processing/consumers/aggregators/state/context.rb', line 32

def offset
  @offset
end

#reportObject (readonly)

Returns the value of attribute report.



32
33
34
# File 'lib/karafka/web/processing/consumers/aggregators/state/context.rb', line 32

def report
  @report
end

#stateObject (readonly)

Returns the value of attribute state.



32
33
34
# File 'lib/karafka/web/processing/consumers/aggregators/state/context.rb', line 32

def state
  @state
end