Class: ActiveJob::QueueAdapters::TestAdapter
Relationships & Source Files | |
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/test_adapter.rb |
Overview
Test adapter for Active Job
The test adapter should be used only in testing. Along with ::ActiveJob::TestCase
and ::ActiveJob::TestHelper
it makes a great tool to test your Rails application.
To use the test adapter set queue_adapter
config to :test
.
Rails.application.config.active_job.queue_adapter = :test
Instance Attribute Summary
- #at rw
-
#enqueued_jobs
rw
Provides a store of all the enqueued jobs with the
TestAdapter
so you can check them. - #enqueued_jobs=(value) rw
- #filter rw
- #perform_enqueued_at_jobs rw
- #perform_enqueued_jobs rw
-
#performed_jobs
rw
Provides a store of all the performed jobs with the
TestAdapter
so you can check them. - #performed_jobs=(value) rw
- #queue rw
- #reject rw
Instance Method Summary
- #filter_as_proc(filter) private
- #filtered?(job) ⇒ Boolean private
- #filtered_job_class?(job) ⇒ Boolean private
- #filtered_queue?(job) ⇒ Boolean private
- #filtered_time?(job) ⇒ Boolean private
- #job_to_hash(job, extras = {}) private
- #perform_or_enqueue(perform, job, job_data) private
- #enqueue(job) Internal use only
- #enqueue_at(job, timestamp) Internal use only
AbstractAdapter
- Inherited
Instance Attribute Details
#at (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 15
attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter, :reject, :queue, :at)
#enqueued_jobs (rw)
Provides a store of all the enqueued jobs with the TestAdapter
so you can check them.
# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 19
def enqueued_jobs @enqueued_jobs ||= [] end
#enqueued_jobs=(value) (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 16
attr_writer(:enqueued_jobs, :performed_jobs)
#filter (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 15
attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter, :reject, :queue, :at)
#perform_enqueued_at_jobs (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 15
attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter, :reject, :queue, :at)
#perform_enqueued_jobs (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 15
attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter, :reject, :queue, :at)
#performed_jobs (rw)
Provides a store of all the performed jobs with the TestAdapter
so you can check them.
# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 24
def performed_jobs @performed_jobs ||= [] end
#performed_jobs=(value) (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 16
attr_writer(:enqueued_jobs, :performed_jobs)
#queue (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 15
attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter, :reject, :queue, :at)
#reject (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 15
attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter, :reject, :queue, :at)
Instance Method Details
#enqueue(job)
This method is for internal use only.
[ GitHub ]
# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 28
def enqueue(job) # :nodoc: job_data = job_to_hash(job) perform_or_enqueue(perform_enqueued_jobs && !filtered?(job), job, job_data) end
#enqueue_at(job, timestamp)
This method is for internal use only.
[ GitHub ]
# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 33
def enqueue_at(job, ) # :nodoc: job_data = job_to_hash(job, at: ) perform_or_enqueue(perform_enqueued_at_jobs && !filtered?(job), job, job_data) end
#filter_as_proc(filter) (private)
[ GitHub ]
#filtered?(job) ⇒ Boolean
(private)
# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 57
def filtered?(job) filtered_queue?(job) || filtered_job_class?(job) || filtered_time?(job) end
#filtered_job_class?(job) ⇒ Boolean
(private)
# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 71
def filtered_job_class?(job) if filter !filter_as_proc(filter).call(job) elsif reject filter_as_proc(reject).call(job) end end
#filtered_queue?(job) ⇒ Boolean
(private)
#filtered_time?(job) ⇒ Boolean
(private)
#job_to_hash(job, extras = {}) (private)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 39
def job_to_hash(job, extras = {}) job.serialize.tap do |job_data| job_data[:job] = job.class job_data[:args] = job_data.fetch("arguments") job_data[:queue] = job_data.fetch("queue_name") job_data[:priority] = job_data.fetch("priority") end.merge(extras) end
#perform_or_enqueue(perform, job, job_data) (private)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 48
def perform_or_enqueue(perform, job, job_data) if perform performed_jobs << job_data Base.execute(job.serialize) else enqueued_jobs << job_data end end