跳到內容 跳到搜尋

Active Job Async 介接卡

Async 介接卡使用內部執行緒池來執行工作。

這是預設佇列介接卡。非常適合用於開發/測試,因為不需要外部基礎架構,但由於此介接卡在重新啟動時會放棄延遲工作,所以不適合用於生產。

若要使用此介接卡,請將佇列介接卡設定為 :async

config.active_job.queue_adapter = :async

若要設定介接卡的執行緒池,請執行下列動作:執行個體化介接卡並傳遞自己的組態

config.active_job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new \
  min_threads: 1,
  max_threads: 2 * Concurrent.processor_count,
  idletime: 600.seconds

介接卡會使用 Concurrent Ruby 執行緒池來排程和執行工作。由於工作共享單一執行緒池,所以長時間執行的工作會阻擋短時間執行的工作。對開發/測試來說很好;但對生產來說很差。

方法
N

類別公共方法

new(**executor\_options)

請參閱 Concurrent::ThreadPoolExecutor 以取得執行器選項。

# File activejob/lib/active_job/queue_adapters/async_adapter.rb, line 35
def initialize(**executor_options)
  @scheduler = Scheduler.new(**executor_options)
end