Skip to content

Allow to run collect blocks in every process of multi-process app #32

Open
@ollym

Description

@ollym

We managed to make this work by adding the following to puma.rb

on_worker_boot(:connection_pool_timer) do |index, data|
  ActiveSupport.on_load(:active_record) do
    data[:connection_pool_timer] = Concurrent::TimerTask.new(execution_interval: 2) do
      ActiveRecord::Base.connection_handler.all_connection_pools.each do |connection_pool|
        tags = { index: index, name: connection_pool.db_config.name }
        connection_pool.stat.each do |name, value|
          Yabeda.activerecord.send(:"connection_pool_#{name}").set(tags, value)
        end
      end
    end.tap(&:execute)
  end
end

on_worker_shutdown(:connection_pool_timer) do |index, data|
  data[:connection_pool_timer]&.shutdown
end

But what do you think about supporting this out the box?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions