-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
Based on rails docs: https://guides.rubyonrails.org/threading_and_code_execution.html#executor
The Rails Executor separates application code from framework code: any time the framework invokes code you've written in your application, it will be wrapped by the Executor.
Here how it can be done in gruf:
app = Rails.application
executor = app.config.reload_classes_only_on_change ? app.reloader : app.executor
Gruf.configure do |c|
c.interceptors.use(Gruf::Interceptors::RailsExecutor, executor: executor)
endInterseptor itself (not tested - code provided as example):
module Gruf
module Interceptors
# Executor runs Rails executor for each call
# See https://guides.rubyonrails.org/v5.2.0/threading_and_code_execution.html#framework-behavior
class RailsExecutor < ::Gruf::Interceptors::ServerInterceptor
def call
options.executor.wrap { yield }
end
end
end
endIn this case no need care about close connections for Activerecord and also fixing issues to other databases (like release connections to redis), which not covered by gruf, but covered by rails.
Also
Before entering the wrapped block, the Reloader will check whether the running application needs to be reloaded
ximus