Class: RactorRailsShim::ArWorkerInitWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/ractor_rails_shim/patches/activerecord.rb

Overview

A shareable Rack middleware that ensures each worker Ractor establishes its own ActiveRecord connection handler on the first request it serves. Kino's :ractor mode has no per-worker init hook, so the connection must be initialized lazily inside the worker Ractor's request path. init_worker_ar_connections! is idempotent (it early-returns once the per-Ractor IES slot holds a handler), so calling it on every request is cheap after the first. The wrapper holds only @app (shareable), so the wrapper itself is Ractor.make_shareable.

Usage in a kino config_ractor.ru:

app = RactorRailsShim.make_app_shareable!(Rails.application)
app = RactorRailsShim.worker_ar_init(app)
run app

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ArWorkerInitWrapper

Returns a new instance of ArWorkerInitWrapper.



1523
1524
1525
# File 'lib/ractor_rails_shim/patches/activerecord.rb', line 1523

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



1527
1528
1529
1530
# File 'lib/ractor_rails_shim/patches/activerecord.rb', line 1527

def call(env)
  RactorRailsShim.init_worker_ar_connections!
  @app.call(env)
end