Skip to content

[Proposal] Replace ConnectionReset to Rails executor #134

@le0pard

Description

@le0pard

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)
end

Interseptor 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
end

In 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

So it may help to reach this #115 and #86

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions