class LogStash::Outputs::Gcs::WorkerPool

WorkerPool creates a pool of workers that can handle jobs.

Attributes

workers[R]

Public Class Methods

new(max_threads, synchronous=false) click to toggle source
# File lib/logstash/outputs/gcs/worker_pool.rb, line 12
def initialize(max_threads, synchronous=false)
  @synchronous = synchronous

  # set queue depth to the be the same as the number of threads so
  # there's at most one pending job each when the plugin quits
  @workers = Concurrent::ThreadPoolExecutor.new(
    min_threads: 1,
    max_threads: max_threads,
    max_queue: max_threads,
    fallback_policy: :caller_runs
  )
end

Public Instance Methods

post(&block) click to toggle source

Submits a job to the worker pool, raises an error if the pool has already been stopped.

# File lib/logstash/outputs/gcs/worker_pool.rb, line 27
def post(&block)
  raise 'Pool already stopped' unless @workers.running?

  if @synchronous
    block.call
  else
    @workers.post do
      block.call
    end
  end
end
stop!() click to toggle source

Stops the worker pool

# File lib/logstash/outputs/gcs/worker_pool.rb, line 40
def stop!
  @workers.shutdown
  @workers.wait_for_termination
end