Class: PatientHttp::Sidekiq::Configuration

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

Overview

Configuration for the Sidekiq Async HTTP gem.

Wraps PatientHttp::Configuration with Sidekiq-aware defaults and adds Sidekiq-specific options like worker queue/retry settings.

Access the underlying pool configuration via the http_pool attribute.

Constant Summary collapse

DEFAULT_PAYLOAD_STORE_THRESHOLD =

Default threshold in bytes above which payloads are stored externally

64 * 1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new Configuration with the specified options.

Parameters:

  • heartbeat_interval (Integer) (defaults to: 60)

    Interval for updating inflight request heartbeats in seconds

  • orphan_threshold (Integer) (defaults to: 300)

    Age threshold for detecting orphaned requests in seconds

  • sidekiq_options (Hash, nil) (defaults to: nil)

    Sidekiq options to apply to RequestWorker and CallbackWorker

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

    Handler called when a CallbackWorker job exhausts retries

  • pool_options (Hash)

    Options passed through to PatientHttp::Configuration. Sidekiq-aware defaults are applied for shutdown_timeout and logger if not explicitly provided.



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

def initialize(
  heartbeat_interval: 60,
  orphan_threshold: 300,
  sidekiq_options: nil,
  payload_store_threshold: DEFAULT_PAYLOAD_STORE_THRESHOLD,
  on_retries_exhausted: nil,
  **pool_options
)
  pool_options[:shutdown_timeout] ||= (::Sidekiq.default_configuration[:timeout] || 25) - 2
  pool_options[:logger] ||= ::Sidekiq.logger

  super(**pool_options)

  @observers = []
  self.sidekiq_options = sidekiq_options
  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/sidekiq/configuration.rb', line 22

def heartbeat_interval
  @heartbeat_interval
end

#observersArray<PatientHttp::ProcessorObserver> (readonly)

Returns Registered processor observers Observers will be registered with the processor when it is started, allowing them to receive lifecycle callbacks for PatientHttp requests.

Returns:

  • (Array<PatientHttp::ProcessorObserver>)

    Registered processor observers Observers will be registered with the processor when it is started, allowing them to receive lifecycle callbacks for PatientHttp requests.



46
47
48
# File 'lib/patient_http/sidekiq/configuration.rb', line 46

def observers
  @observers
end

#orphan_thresholdNumeric

Returns Orphan detection threshold in seconds.

Returns:

  • (Numeric)

    Orphan detection threshold in seconds



19
20
21
# File 'lib/patient_http/sidekiq/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/sidekiq/configuration.rb', line 16

def payload_store_threshold
  @payload_store_threshold
end

#sidekiq_optionsHash?

Returns Sidekiq options to apply to RequestWorker and CallbackWorker.

Returns:

  • (Hash, nil)

    Sidekiq options to apply to RequestWorker and CallbackWorker



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

def sidekiq_options
  @sidekiq_options
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/sidekiq/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



85
86
87
88
89
90
91
# File 'lib/patient_http/sidekiq/configuration.rb', line 85

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

#to_hHash

Convert to hash for inspection

Returns:

  • (Hash)

    hash representation with string keys



149
150
151
152
153
154
155
156
157
# File 'lib/patient_http/sidekiq/configuration.rb', line 149

def to_h
  super.merge(
    "payload_store_threshold" => payload_store_threshold,
    "heartbeat_interval" => heartbeat_interval,
    "orphan_threshold" => orphan_threshold,
    "sidekiq_options" => sidekiq_options,
    "on_retries_exhausted" => on_retries_exhausted ? "defined" : nil
  )
end