Module: Sidekiq::Worker::ClassMethods

Defined in:
lib/sidekiq_unique_jobs/testing.rb

Overview

Adds class methods to Sidekiq::Worker

Instance Method Summary collapse

Instance Method Details

#clearObject

Clears the jobs for this worker and removes all locks



78
79
80
81
82
83
84
85
# File 'lib/sidekiq_unique_jobs/testing.rb', line 78

def clear
  jobs.each do |job|
    SidekiqUniqueJobs::Unlockable.unlock(job)
  end

  Sidekiq::Queues[queue].clear
  jobs.clear
end

#use_options(tmp_config = {}) ⇒ Object

Note:

this method will restore the original configuration after yielding

Temporarily turn a workers sidekiq_options into something different

Parameters:

  • tmp_config (Hash<Symbol, Object>) (defaults to: {})

    the temporary config to use



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sidekiq_unique_jobs/testing.rb', line 59

def use_options(tmp_config = {})
  old_options = sidekiq_options_hash.dup
  sidekiq_options(old_options.merge(tmp_config))

  yield
ensure
  self.sidekiq_options_hash =
    if Sidekiq.respond_to?(:default_job_options)
      Sidekiq.default_job_options
    else
      DEFAULT_WORKER_OPTIONS
    end

  sidekiq_options(old_options)
end