Class: Pgbus::Streams::PoolAutoscaler::Maintenance

Inherits:
Object
  • Object
show all
Defined in:
lib/pgbus/streams/pool_autoscaler.rb

Overview

Wraps an autoscaler as a Listener maintenance task: on each throttled idle window the Listener calls #run(conn); this queries live headroom on THAT connection (the streamer's existing LISTEN connection — no extra connection) and hands it to the autoscaler. interval is the throttle (seconds) the Listener honors between runs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(autoscaler:, interval:, application_name_prefix:) ⇒ Maintenance

Returns a new instance of Maintenance.



183
184
185
186
187
# File 'lib/pgbus/streams/pool_autoscaler.rb', line 183

def initialize(autoscaler:, interval:, application_name_prefix:)
  @autoscaler = autoscaler
  @interval = interval
  @like = "#{application_name_prefix}_%"
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



181
182
183
# File 'lib/pgbus/streams/pool_autoscaler.rb', line 181

def interval
  @interval
end

Instance Method Details

#run(conn) ⇒ Object



189
190
191
192
193
194
195
196
197
198
# File 'lib/pgbus/streams/pool_autoscaler.rb', line 189

def run(conn)
  row = conn.exec_params(HEADROOM_SQL, [@like]).first
  # Explicit positional hash (braces) — evaluate now takes an optional
  # allow_shrink: keyword, so a bare hash would be parsed as keywords.
  # The streamer allows shrink (it sees the sustained idle picture).
  @autoscaler.evaluate(
    { maxc: row["maxc"].to_i, used: row["used"].to_i, peers: row["peers"].to_i },
    allow_shrink: true
  )
end