Skip to content

Commit

Permalink
Add database_connection_pool stats to GoodJob::Process.current_state (
Browse files Browse the repository at this point in the history
TheOdinProject#1019)

* Add connection_pool stats to `GoodJob::Process.current_stat`

This commit adds snapshot of database connection pool to a
`GoodJob::Process.current_stat` method.

* `size` - Total capacity of connection pool
* `active` - Number of connections in the pool that are in_use/active

* Rename `database_connection_pool` and add simple test

---------

Co-authored-by: Ben Sheldon [he/him] <bensheldon@gmail.com>
  • Loading branch information
dixpac and bensheldon committed Jul 27, 2023
1 parent 573ec04 commit bbf5d22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/good_job/process.rb
Expand Up @@ -63,6 +63,10 @@ def self.ns_current_state
cron_enabled: GoodJob.configuration.enable_cron?,
total_succeeded_executions_count: GoodJob::Scheduler.instances.sum { |scheduler| scheduler.stats.fetch(:succeeded_executions_count) },
total_errored_executions_count: GoodJob::Scheduler.instances.sum { |scheduler| scheduler.stats.fetch(:errored_executions_count) },
database_connection_pool: {
size: connection_pool.size,
active: connection_pool.connections.count(&:in_use?),
},
}
end

Expand Down
11 changes: 11 additions & 0 deletions spec/app/models/good_job/process_spec.rb
Expand Up @@ -23,6 +23,17 @@
end
end

describe '.ns_current_state' do
it 'contains information about the process' do
expect(described_class.ns_current_state).to include(
database_connection_pool: include(
size: be_an(Integer),
active: be_an(Integer)
)
)
end
end

describe '.register' do
it 'registers the process' do
process = nil
Expand Down

0 comments on commit bbf5d22

Please sign in to comment.