Class: Airflow::Executors::ThreadPoolExecutor

Inherits:
Object
  • Object
show all
Includes:
Utils::Logger
Defined in:
lib/async_flow/executors.rb

Overview

TODO: Replace with ruby-concurrent TODO: min, masx threads TODO: queue size

Instance Method Summary collapse

Methods included from Utils::Logger

#logger

Constructor Details

#initialize(size) ⇒ ThreadPoolExecutor

Returns a new instance of ThreadPoolExecutor.



11
12
13
14
15
16
17
18
# File 'lib/async_flow/executors.rb', line 11

def initialize(size)
  @jobs = Queue.new
  @pool = Array.new(size) do
    Thread.new do
      poll
    end
  end
end

Instance Method Details

#post(*args, &block) ⇒ Object



20
21
22
23
# File 'lib/async_flow/executors.rb', line 20

def post(*args, &block)
  # assert!
  jobs << [block, args]
end

#shutdownObject



25
26
27
28
29
30
31
32
33
# File 'lib/async_flow/executors.rb', line 25

def shutdown
  logger.info "shutting down executor"
  pool.size.times do
    post { throw :exit }
  end

  pool.each(&:join)
  logger.info "executor shut down"
end