diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-02-06 17:17:18 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-02-06 17:17:18 -0200 |
commit | decb7b66d040eafbbf03e4533672eb135d49a036 (patch) | |
tree | de3f0747cbe4d47896fa6bb8f5af170cc899fbb4 /activejob/lib/active_job/queue_adapters | |
parent | ec6c98f7d11e53811fbaa13ed521386f53011630 (diff) | |
parent | e818f65770fe115ab1cc7fbacc0e7e94d92af6a4 (diff) | |
download | rails-decb7b66d040eafbbf03e4533672eb135d49a036.tar.gz rails-decb7b66d040eafbbf03e4533672eb135d49a036.tar.bz2 rails-decb7b66d040eafbbf03e4533672eb135d49a036.zip |
Merge pull request #18833 from perceptec/add_only_performed_option
Add an `:only` option to `perform_enqueued_jobs` to filter jobs based on type.
Diffstat (limited to 'activejob/lib/active_job/queue_adapters')
-rw-r--r-- | activejob/lib/active_job/queue_adapters/test_adapter.rb | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb index ea9df9a063..c9e2bdca27 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -11,7 +11,7 @@ module ActiveJob # Rails.application.config.active_job.queue_adapter = :test class TestAdapter delegate :name, to: :class - attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs) + attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter) attr_writer(:enqueued_jobs, :performed_jobs) def initialize @@ -30,22 +30,33 @@ module ActiveJob end def enqueue(job) #:nodoc: - if perform_enqueued_jobs - performed_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name} - Base.execute job.serialize - else - enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name} - end + return if filtered?(job) + + job_data = { job: job.class, args: job.serialize['arguments'], queue: job.queue_name } + enqueue_or_perform(perform_enqueued_jobs, job, job_data) end def enqueue_at(job, timestamp) #:nodoc: - if perform_enqueued_at_jobs - performed_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: timestamp} - Base.execute job.serialize - else - enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: timestamp} - end + return if filtered?(job) + + job_data = { job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: timestamp } + enqueue_or_perform(perform_enqueued_at_jobs, job, job_data) end + + private + + def enqueue_or_perform(perform, job, job_data) + if perform + performed_jobs << job_data + Base.execute job.serialize + else + enqueued_jobs << job_data + end + end + + def filtered?(job) + filter && !Array(filter).include?(job.class) + end end end end |