Rails Executor
https://guides.rubyonrails.org/threading_and_code_execution.html#executor
ユーザーコードをRailsに実行させるとき、Executorによってラップさせる
Procやblockを渡すだけではDBコネクションなどのリソースのclearn upなどを正しく行えない
ラップされたコードは以下の機能を獲得する
定期的なオートロードとリロード
データベース接続/接続プールの管理とクエリの再試行
クエリキャッシュ
クエリロギング
現在の属性
エラー報告
この機構をRails Executorと呼ぶ
code:ruby
Rails.application.executor.wrap do
# call application code here
end
https://envek.github.io/kaigionrails-rails-executor
Executorの説明、および修正したgemの話
action_policy
https://github.com/palkan/action_policy/blob/8204e9b82f2767728dce69fccb5c4b2088c532ec/lib/action_policy/railtie.rb#L59-L61
nats-pure
https://github.com/nats-io/nats-pure.rb/pull/120
The Rails Executor: increasingly everywhere
Rails 7.1以降はrails runnberで実行されるスクリプトやminitestのテストケースもexecutorでラップされるようになった
長時間のスクリプトが実行される可能性があるようなrails runnerでは--skip-executorでラップを回避できる
https://github.com/rails/rails/pull/50223