Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ollym opened this issue Feb 19, 2023 · 1 comment
Open

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

ollym opened this issue Feb 19, 2023 · 1 comment

Comments

@ollym
Copy link

ollym commented Feb 19, 2023

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?

@Envek
Copy link
Member

Envek commented Dec 13, 2023

Thanks for providing a code example and sorry for late reply.

Yeah, it is a good idea to support it out of the box, but it will require some API changes in Yabeda itself and yabeda-puma-plugin also.

@Envek Envek transferred this issue from yabeda-rb/yabeda-activerecord Dec 13, 2023
@Envek Envek changed the title Doesn't work in puma clustered mode Allow to run collect blocks in every process of multi-process app Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants