Class: ActiveJob::QueueAdapters::AsyncAdapter
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
AbstractAdapter
|
|
Instance Chain:
self,
AbstractAdapter
|
|
Inherits: |
ActiveJob::QueueAdapters::AbstractAdapter
|
Defined in: | activejob/lib/active_job/queue_adapters/async_adapter.rb |
Overview
Active Job Async adapter
The Async adapter runs jobs with an in-process thread pool.
This is the default queue adapter. It’s well-suited for dev/test since it doesn’t need an external infrastructure, but it’s a poor fit for production since it drops pending jobs on restart.
To use this adapter, set queue adapter to :async
:
config.active_job.queue_adapter = :async
To configure the adapter’s thread pool, instantiate the adapter and pass your own config:
config.active_job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new \
min_threads: 1,
max_threads: 2 * Concurrent.processor_count,
idletime: 600.seconds
The adapter uses a Concurrent Ruby thread pool to schedule and execute jobs. Since jobs share a single thread pool, long-running jobs will block short-lived jobs. Fine for dev/test; bad for production.
Class Method Summary
-
.new(**executor_options) ⇒ AsyncAdapter
constructor
See Concurrent::ThreadPoolExecutor for executor options.
Instance Attribute Summary
-
#immediate=(immediate)
writeonly
Internal use only
Used for our test suite.
Instance Method Summary
- #enqueue(job) Internal use only
- #enqueue_at(job, timestamp) Internal use only
-
#shutdown(wait: true)
Internal use only
Gracefully stop processing jobs.
AbstractAdapter
- Inherited
Constructor Details
.new(**executor_options) ⇒ AsyncAdapter
See Concurrent::ThreadPoolExecutor for executor options.
Instance Attribute Details
#immediate=(immediate) (writeonly)
Used for our test suite.
# File 'activejob/lib/active_job/queue_adapters/async_adapter.rb', line 55
def immediate=(immediate) # :nodoc: @scheduler.immediate = immediate end
Instance Method Details
#enqueue(job)
# File 'activejob/lib/active_job/queue_adapters/async_adapter.rb', line 39
def enqueue(job) # :nodoc: @scheduler.enqueue JobWrapper.new(job), queue_name: job.queue_name end
#enqueue_at(job, timestamp)
# File 'activejob/lib/active_job/queue_adapters/async_adapter.rb', line 43
def enqueue_at(job, ) # :nodoc: @scheduler.enqueue_at JobWrapper.new(job), , queue_name: job.queue_name end
#shutdown(wait: true)
Gracefully stop processing jobs. Finishes in-progress work and handles any new jobs following the executor’s fallback policy (caller_runs
). Waits for termination by default. Pass wait: false
to continue.
# File 'activejob/lib/active_job/queue_adapters/async_adapter.rb', line 50
def shutdown(wait: true) # :nodoc: @scheduler.shutdown wait: wait end