Class: PatientHttp::SolidQueue::Configuration

Inherits:
Configuration
  • Object
show all
Defined in:
lib/patient_http/solid_queue/configuration.rb

Overview

Configuration for the Solid Queue Async HTTP gem.

Wraps PatientHttp::Configuration with Solid Queue-aware defaults and adds Solid Queue-specific options like queue name settings.

Defined Under Namespace

Classes: ProfileConfiguration

Constant Summary collapse

DEFAULT_PAYLOAD_STORE_THRESHOLD =

Default threshold in bytes above which payloads are stored externally.

64 * 1024
SHUTDOWN_TIMEOUT_BUFFER =

Buffer in seconds subtracted from SolidQueue.shutdown_timeout to derive the default shutdown_timeout for this gem's connection pool.

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(heartbeat_interval: 60, orphan_threshold: 300, queue_name: nil, payload_store_threshold: DEFAULT_PAYLOAD_STORE_THRESHOLD, on_retries_exhausted: nil, **pool_options) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • heartbeat_interval (Numeric) (defaults to: 60)

    Interval in seconds for heartbeat updates (default: 60)

  • orphan_threshold (Numeric) (defaults to: 300)

    Time in seconds to consider a job orphaned (default: 300)

  • queue_name (String, nil) (defaults to: nil)

    Optional queue name for RequestJob and CallbackJob (default: nil)

  • payload_store_threshold (Integer) (defaults to: DEFAULT_PAYLOAD_STORE_THRESHOLD)

    Size threshold in bytes for external payload storage (default: 64KB)

  • on_retries_exhausted (#call, nil) (defaults to: nil)

    Handler called when a CallbackWorker job exhausts retries

  • pool_options (Hash)

    Additional options passed to the SolidQueue connection pool



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/patient_http/solid_queue/configuration.rb', line 53

def initialize(
  heartbeat_interval: 60,
  orphan_threshold: 300,
  queue_name: nil,
  payload_store_threshold: DEFAULT_PAYLOAD_STORE_THRESHOLD,
  on_retries_exhausted: nil,
  **pool_options
)
  if ::SolidQueue.shutdown_timeout
    pool_options[:shutdown_timeout] ||= [::SolidQueue.shutdown_timeout - SHUTDOWN_TIMEOUT_BUFFER, 1].max
  end
  pool_options[:user_agent] ||= "SolidQueue-AsyncHttp"
  pool_options[:logger] ||= (defined?(SolidQueue.logger) ? SolidQueue.logger : nil)

  super(**pool_options)

  @processor_profiles = {default: {}}
  self.queue_name = queue_name
  self.heartbeat_interval = heartbeat_interval
  self.orphan_threshold = orphan_threshold
  self.payload_store_threshold = payload_store_threshold || DEFAULT_PAYLOAD_STORE_THRESHOLD
  self.on_retries_exhausted = on_retries_exhausted
end

Instance Attribute Details

#heartbeat_intervalNumeric

Returns Heartbeat update interval in seconds.

Returns:

  • (Numeric)

    Heartbeat update interval in seconds



22
23
24
# File 'lib/patient_http/solid_queue/configuration.rb', line 22

def heartbeat_interval
  @heartbeat_interval
end

#orphan_thresholdNumeric

Returns Orphan detection threshold in seconds.

Returns:

  • (Numeric)

    Orphan detection threshold in seconds



19
20
21
# File 'lib/patient_http/solid_queue/configuration.rb', line 19

def orphan_threshold
  @orphan_threshold
end

#payload_store_thresholdInteger

Returns Size threshold in bytes for external payload storage.

Returns:

  • (Integer)

    Size threshold in bytes for external payload storage



16
17
18
# File 'lib/patient_http/solid_queue/configuration.rb', line 16

def payload_store_threshold
  @payload_store_threshold
end

#queue_nameString?

Returns Queue name for RequestJob and CallbackJob.

Returns:

  • (String, nil)

    Queue name for RequestJob and CallbackJob



25
26
27
# File 'lib/patient_http/solid_queue/configuration.rb', line 25

def queue_name
  @queue_name
end

Instance Method Details

#on_retries_exhausted#call? #on_retries_exhausted {|error| ... } ⇒ #call?

Returns Handler invoked when a CallbackWorker job exhausts all retries.

Overloads:

  • #on_retries_exhausted#call?

    Returns the current handler.

    Returns:

    • (#call, nil)
  • #on_retries_exhausted {|error| ... } ⇒ #call?

    Sets a block as the handler.

    Yields:

    • (error)

      block to execute when retries are exhausted

    Yield Parameters:

    • error (PatientHttp::Error)

      information about the error

Returns:

  • (#call, nil)

    Handler invoked when a CallbackWorker job exhausts all retries.



35
36
37
38
39
40
41
# File 'lib/patient_http/solid_queue/configuration.rb', line 35

def on_retries_exhausted(&block)
  if block
    @on_retries_exhausted = block
  else
    @on_retries_exhausted
  end
end

#on_retries_exhausted=(value) ⇒ Object

Set the on_retries_exhausted handler.

This handler is called when a CallbackWorker job exhausts all retries. It receives the same arguments as the on_error callback.

Parameters:

  • value (#call, nil)

    A callable object or nil to clear the handler

Raises:

  • (ArgumentError)

    If value is not callable and not nil



170
171
172
173
174
175
176
# File 'lib/patient_http/solid_queue/configuration.rb', line 170

def on_retries_exhausted=(value)
  if value && !value.respond_to?(:call)
    raise ArgumentError.new("on_retries_exhausted must respond to #call, got: #{value.class}")
  end

  @on_retries_exhausted = value
end

#processor(name, **options) ⇒ Hash

Declare a named processor profile.

Each profile becomes an independent processor with its own capacity, timeouts, and threads. Options are overrides applied on top of this configuration's HTTP pool options. Calling this with no options declares a profile that inherits every option. Requests select a processor with the processor: option on PatientHttp::SolidQueue.execute (or on the request itself). The :default profile always exists; declaring it overrides options for the default processor.

Examples:

PatientHttp::SolidQueue.configure do |config|
  config.processor(:llm, max_connections: 200, request_timeout: 120)
  config.processor(:webhooks, max_connections: 64, request_timeout: 10)
end

Parameters:

  • name (Symbol, String)

    the processor name

  • options (Hash)

    overrides for PatientHttp::Configuration options

Returns:

  • (Hash)

    the stored options for the profile



97
98
99
100
# File 'lib/patient_http/solid_queue/configuration.rb', line 97

def processor(name, **options)
  key = normalize_processor_name(name)
  @processor_profiles[key] = normalize_profile_options!(options)
end

#processor_config(name) ⇒ PatientHttp::Configuration

Build the effective configuration for a named processor. The default profile with no overrides is this configuration itself; other profiles get a view of this configuration with their overrides applied, so they share secrets, preprocessors, payload stores, and encryption.

Parameters:

  • name (Symbol, String)

    the processor name

Returns:

  • (PatientHttp::Configuration)

    the configuration for the processor

Raises:

  • (ArgumentError)

    if the profile is not declared



125
126
127
128
129
130
131
132
133
# File 'lib/patient_http/solid_queue/configuration.rb', line 125

def processor_config(name)
  key = normalize_processor_name(name)
  profile = @processor_profiles[key]
  raise ArgumentError.new("Unknown processor profile: #{name.inspect}") unless profile

  return self if profile.empty?

  ProfileConfiguration.new(self, profile)
end

#processor_options(name) ⇒ Hash?

Read back the options declared for a named processor profile.

Parameters:

  • name (Symbol, String)

    the processor name

Returns:

  • (Hash, nil)

    the stored options, or nil if the profile is not declared



106
107
108
# File 'lib/patient_http/solid_queue/configuration.rb', line 106

def processor_options(name)
  @processor_profiles[normalize_processor_name(name)]
end

#processor_profilesHash{Symbol => Hash}

All declared processor profiles. Always includes :default.

Returns:

  • (Hash{Symbol => Hash})

    profile options by processor name



113
114
115
# File 'lib/patient_http/solid_queue/configuration.rb', line 113

def processor_profiles
  @processor_profiles.dup
end

#to_hHash

Returns configuration as a hash for logging/inspection.

Returns:

  • (Hash)

    configuration as a hash for logging/inspection



179
180
181
182
183
184
185
186
187
188
# File 'lib/patient_http/solid_queue/configuration.rb', line 179

def to_h
  super.merge(
    "payload_store_threshold" => payload_store_threshold,
    "heartbeat_interval" => heartbeat_interval,
    "orphan_threshold" => orphan_threshold,
    "queue_name" => queue_name,
    "on_retries_exhausted" => on_retries_exhausted ? "defined" : nil,
    "processor_profiles" => processor_profiles.keys.map(&:to_s)
  )
end