Class: SolidQueueGuard::Checks::Config::ThreadPoolCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/solid_queue_guard/checks/config/thread_pool_check.rb

Instance Method Summary collapse

Methods inherited from Base

call, check_id, #initialize

Constructor Details

This class inherits a constructor from SolidQueueGuard::Checks::Base

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/solid_queue_guard/checks/config/thread_pool_check.rb', line 7

def call
  required_threads = solid_queue_configuration.send(:estimated_number_of_threads)
  pool_size = SolidQueue::Record.connection_pool&.size

  return skip('thread_pool', 'Queue database connection pool is not available') if pool_size.nil?

  max_worker_threads = solid_queue_configuration.send(:workers_options)
                                                .map do |options|
    options.fetch(
      :threads, 3
    )
  end.max || 1

  if pool_size >= required_threads
    pass(
      'thread_pool',
      "Worker threads: #{max_worker_threads}, queue DB pool: #{pool_size}",
      metadata: { threads: max_worker_threads, pool: pool_size, required: required_threads }
    )
  else
    failure(
      'thread_pool',
      "Worker threads: #{max_worker_threads}, queue DB pool: #{pool_size}",
      suggestion: "Increase queue DB pool to at least #{required_threads} or reduce worker threads",
      metadata: { threads: max_worker_threads, pool: pool_size, required: required_threads }
    )
  end
end