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。
来源: 显示 | 在 GitHub 上
# File activejob/lib/active_job/queue_adapters/async_adapter.rb, line 35 def initialize(**executor_options) @scheduler = Scheduler.new(**executor_options) end