Class: Solrengine::Sdp::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/solrengine/sdp/configuration.rb

Overview

Engine configuration: explicit attributes with ENV fallbacks (rpc/auth family pattern — a real class, not bare mattr_accessor).

Solrengine::Sdp.configure do |config|
  config.api_key    = Rails.application.credentials.dig(:sdp, :api_key)
  config.user_class = "Account"
end

Constant Summary collapse

DEFAULT_BASE_URL =
"http://127.0.0.1:8787"
DEFAULT_EXPIRED_TRANSFER_DEADLINE =

seconds

15 * 60
DEFAULT_TRANSFER_POLL_INTERVAL =

seconds — confirmation is usually seconds away

3
DEFAULT_PROVISIONING_LEASE =

seconds — see provisioning_lease below

10 * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/solrengine/sdp/configuration.rb', line 28

def initialize
  @user_class = "User"
  @expired_transfer_deadline = DEFAULT_EXPIRED_TRANSFER_DEADLINE
  @transfer_poll_interval = DEFAULT_TRANSFER_POLL_INTERVAL
  @provisioning_lease = DEFAULT_PROVISIONING_LEASE
  @broadcast_retry_delay = 2
  @broadcast_retries = 3
  # Ordered array of {name:, fetch:, render:} hashes — see Broadcaster.
  # Empty by default: the Broadcaster logs a hint and broadcasts
  # nothing until the app configures its targets.
  @broadcast_targets = []
end

Instance Attribute Details

#api_keyObject



41
42
43
# File 'lib/solrengine/sdp/configuration.rb', line 41

def api_key
  @api_key || ENV["SDP_API_KEY"]
end

#base_urlObject



45
46
47
# File 'lib/solrengine/sdp/configuration.rb', line 45

def base_url
  @base_url || ENV.fetch("SDP_API_BASE_URL", DEFAULT_BASE_URL)
end

#broadcast_retriesObject

provisioning_lease (seconds): how long a wallet-owner row may sit in “provisioning” untouched before the claim is considered abandoned (worker died between claim and settle) and another job may take it over. Any live job renews the row’s updated_at well within this window, so a takeover can only hit a genuinely dead claim.



24
25
26
# File 'lib/solrengine/sdp/configuration.rb', line 24

def broadcast_retries
  @broadcast_retries
end

#broadcast_retry_delayObject

provisioning_lease (seconds): how long a wallet-owner row may sit in “provisioning” untouched before the claim is considered abandoned (worker died between claim and settle) and another job may take it over. Any live job renews the row’s updated_at well within this window, so a takeover can only hit a genuinely dead claim.



24
25
26
# File 'lib/solrengine/sdp/configuration.rb', line 24

def broadcast_retry_delay
  @broadcast_retry_delay
end

#broadcast_targetsObject

provisioning_lease (seconds): how long a wallet-owner row may sit in “provisioning” untouched before the claim is considered abandoned (worker died between claim and settle) and another job may take it over. Any live job renews the row’s updated_at well within this window, so a takeover can only hit a genuinely dead claim.



24
25
26
# File 'lib/solrengine/sdp/configuration.rb', line 24

def broadcast_targets
  @broadcast_targets
end

#custody_providerObject



49
50
51
# File 'lib/solrengine/sdp/configuration.rb', line 49

def custody_provider
  @custody_provider || ENV["SDP_CUSTODY_PROVIDER"]
end

#expired_transfer_deadlineObject

provisioning_lease (seconds): how long a wallet-owner row may sit in “provisioning” untouched before the claim is considered abandoned (worker died between claim and settle) and another job may take it over. Any live job renews the row’s updated_at well within this window, so a takeover can only hit a genuinely dead claim.



24
25
26
# File 'lib/solrengine/sdp/configuration.rb', line 24

def expired_transfer_deadline
  @expired_transfer_deadline
end

#label_namespaceObject

Prefix for SDP wallet labels (“##label_namespace-user-#id”). Defaults to the Rails application name, else “app”.



55
56
57
# File 'lib/solrengine/sdp/configuration.rb', line 55

def label_namespace
  @label_namespace || default_label_namespace
end

#loggerObject

Engine log sink: Rails.logger in a Rails host, $stdout otherwise. Tests assign a StringIO-backed logger to assert on log lines.



67
68
69
# File 'lib/solrengine/sdp/configuration.rb', line 67

def logger
  @logger ||= default_logger
end

#provisioning_leaseObject

provisioning_lease (seconds): how long a wallet-owner row may sit in “provisioning” untouched before the claim is considered abandoned (worker died between claim and settle) and another job may take it over. Any live job renews the row’s updated_at well within this window, so a takeover can only hit a genuinely dead claim.



24
25
26
# File 'lib/solrengine/sdp/configuration.rb', line 24

def provisioning_lease
  @provisioning_lease
end

#transfer_poll_intervalObject

provisioning_lease (seconds): how long a wallet-owner row may sit in “provisioning” untouched before the claim is considered abandoned (worker died between claim and settle) and another job may take it over. Any live job renews the row’s updated_at well within this window, so a takeover can only hit a genuinely dead claim.



24
25
26
# File 'lib/solrengine/sdp/configuration.rb', line 24

def transfer_poll_interval
  @transfer_poll_interval
end

#user_classObject

provisioning_lease (seconds): how long a wallet-owner row may sit in “provisioning” untouched before the claim is considered abandoned (worker died between claim and settle) and another job may take it over. Any live job renews the row’s updated_at well within this window, so a takeover can only hit a genuinely dead claim.



24
25
26
# File 'lib/solrengine/sdp/configuration.rb', line 24

def user_class
  @user_class
end

Instance Method Details

#user_modelObject

Lazily constantized so the engine can be configured before the app’s user model is loadable (initializer-time safe).



61
62
63
# File 'lib/solrengine/sdp/configuration.rb', line 61

def user_model
  Object.const_get(user_class)
end

#validate!Object

Boot check used by the engine’s after_initialize hook, also callable directly. A missing key must fail loudly at boot, not at the first wallet call.

Raises:



74
75
76
77
78
79
80
81
82
# File 'lib/solrengine/sdp/configuration.rb', line 74

def validate!
  return self unless api_key.to_s.strip.empty?

  raise ConfigurationError,
    "Solrengine::Sdp api_key is not set. The engine cannot talk to the SDP API without it. " \
    "Set the SDP_API_KEY environment variable (start the local SDP stack and export the " \
    "seeded key) or assign config.api_key in a Solrengine::Sdp.configure block. " \
    "Optionally set SDP_API_BASE_URL (default: #{DEFAULT_BASE_URL})."
end