Class: GoodJob::Scheduler::ThreadPoolExecutor

Inherits:
Concurrent::ThreadPoolExecutor
  • Object
show all
Defined in:
lib/good_job/scheduler.rb

Overview

Custom sub-class of Concurrent::ThreadPoolExecutor to add additional worker status.

Instance Method Summary collapse

Instance Method Details

#ready_worker_countInteger

Number of inactive threads available to execute tasks. github.com/ruby-concurrency/concurrent-ruby/issues/684#issuecomment-427594437

Returns:

  • (Integer)


312
313
314
315
316
317
318
319
320
321
322
# File 'lib/good_job/scheduler.rb', line 312

def ready_worker_count
  synchronize do
    if Concurrent.on_jruby?
      @executor.getMaximumPoolSize - @executor.getActiveCount
    else
      workers_still_to_be_created = @max_length - @pool.length
      workers_created_but_waiting = @ready.length
      workers_still_to_be_created + workers_created_but_waiting
    end
  end
end