Module: Sidekiq::Worker::ClassMethods
- Defined in:
- lib/sidekiq/testing.rb,
lib/sidekiq/worker.rb
Overview
The Sidekiq testing infrastructure overrides perform_async so that it does not actually touch the network. Instead it stores the asynchronous jobs in a per-class array so that their presence/absence can be asserted by your tests.
This is similar to ActionMailer’s :test delivery_method and its ActionMailer::Base.deliveries array.
Example:
require 'sidekiq/testing'
assert_equal 0, HardWorker.jobs.size
HardWorker.perform_async(:something)
assert_equal 1, HardWorker.jobs.size
assert_equal :something, HardWorker.jobs[0]['args'][0]
Instance Method Summary collapse
-
#get_sidekiq_options ⇒ Object
:nodoc:.
- #jobs ⇒ Object
- #perform_async(*args) ⇒ Object
- #perform_async_old ⇒ Object
- #queue(name) ⇒ Object
-
#sidekiq_options(opts = {}) ⇒ Object
Allows customization for this type of Worker.
-
#stringify_keys(hash) ⇒ Object
:nodoc:.
Instance Method Details
#get_sidekiq_options ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/sidekiq/worker.rb', line 48 def # :nodoc: @sidekiq_options || { 'unique' => true, 'retry' => true, 'queue' => 'default' } end |
#jobs ⇒ Object
29 30 31 |
# File 'lib/sidekiq/testing.rb', line 29 def jobs @pushed ||= [] end |
#perform_async(*args) ⇒ Object
28 29 30 |
# File 'lib/sidekiq/worker.rb', line 28 def perform_async(*args) Sidekiq::Client.push('class' => self, 'args' => args) end |
#perform_async_old ⇒ Object
23 24 25 |
# File 'lib/sidekiq/testing.rb', line 23 def perform_async(*args) Sidekiq::Client.push('class' => self, 'args' => args) end |
#queue(name) ⇒ Object
32 33 34 35 |
# File 'lib/sidekiq/worker.rb', line 32 def queue(name) puts "DEPRECATED: `queue :name` is now `sidekiq_options :queue => :name`" Sidekiq::Client.queue_mappings[self.name] = name.to_s end |
#sidekiq_options(opts = {}) ⇒ Object
Allows customization for this type of Worker. Legal options:
:unique - enable the UniqueJobs middleware for this Worker, default *true*
:queue - use a named queue for this Worker, default 'default'
:retry - enable the RetryJobs middleware for this Worker, default *true*
44 45 46 |
# File 'lib/sidekiq/worker.rb', line 44 def (opts={}) @sidekiq_options = .merge(stringify_keys(opts || {})) end |
#stringify_keys(hash) ⇒ Object
:nodoc:
52 53 54 55 56 57 |
# File 'lib/sidekiq/worker.rb', line 52 def stringify_keys(hash) # :nodoc: hash.keys.each do |key| hash[key.to_s] = hash.delete(key) end hash end |