Class: Apidepth::RegistryLoader
- Inherits:
-
Object
- Object
- Apidepth::RegistryLoader
- Defined in:
- lib/apidepth/registry_loader.rb
Constant Summary collapse
- REGISTRY_URL =
"https://collector.apidepth.io/v1/registry".freeze
Class Method Summary collapse
-
.load_and_start ⇒ Object
Called by the Railtie after_initialize.
-
.reset_state! ⇒ Object
Reset mutable class-level warn state under @mutex.
Class Method Details
.load_and_start ⇒ Object
Called by the Railtie after_initialize. Loads the best available registry (remote → disk cache → bundled baseline already loaded by VendorRegistry.initialize_registry) and starts the background refresh thread.
Startup strategy: apply the on-disk cache synchronously so the in-process registry is populated immediately (no blocking network call on the boot thread). The initial remote fetch is dispatched to a background thread so that slow or unreachable endpoints (CI, air-gapped environments) do not block Rails boot for up to 8 seconds (open_timeout + read_timeout). The background refresh loop (start_refresh_thread) is unchanged.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/apidepth/registry_loader.rb', line 22 def self.load_and_start # Apply disk cache immediately — zero network latency, registry is ready # before the application begins serving requests. disk_registry = load_from_disk VendorRegistry.replace(disk_registry) if disk_registry # Fetch the freshest registry from the network in the background so the # boot thread is never blocked by the remote request. Thread.new do registry = fetch_remote VendorRegistry.replace(registry) if registry end.tap do |t| t.abort_on_exception = false t.name = "apidepth-registry-init" end start_refresh_thread end |
.reset_state! ⇒ Object
Reset mutable class-level warn state under @mutex. Called by tests instead of raw instance_variable_set so that state changes go through the same lock used in production code paths.
237 238 239 240 241 242 243 |
# File 'lib/apidepth/registry_loader.rb', line 237 def self.reset_state! @mutex.synchronize do @conflict_vendors = {} @warned_stale = {} @warned_conflict = {} end end |