Module: Sidekiq::Worker

Included in:
Extensions::DelayedClass, Extensions::DelayedMailer, Extensions::DelayedModel
Defined in:
lib/sidekiq/worker.rb,
lib/sidekiq/testing.rb

Overview

Include this module in your worker class and you can easily create asynchronous jobs:

class HardWorker

include Sidekiq::Worker

def perform(*args)
  # do some work
end

end

Then in your Rails app, you can do this:

HardWorker.perform_async(1, 2, 3)

Note that perform_async is a class method, perform is an instance method.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#jidObject

Returns the value of attribute jid



24
25
26
# File 'lib/sidekiq/worker.rb', line 24

def jid
  @jid
end

Class Method Details

.clear_allObject

Clear all queued jobs across all workers



179
180
181
# File 'lib/sidekiq/testing.rb', line 179

def clear_all
  jobs.clear
end

.drain_allObject

Drain all queued jobs across all workers



184
185
186
187
188
# File 'lib/sidekiq/testing.rb', line 184

def drain_all
  until jobs.values.all?(&:empty?) do
    jobs.keys.each(&:drain)
  end
end

.included(base) ⇒ Object



26
27
28
29
30
31
# File 'lib/sidekiq/worker.rb', line 26

def self.included(base)
  base.extend(ClassMethods)
  base.class_attribute :sidekiq_options_hash
  base.class_attribute :sidekiq_retry_in_block
  base.class_attribute :sidekiq_retries_exhausted_block
end

.jobsObject

:nodoc:



174
175
176
# File 'lib/sidekiq/testing.rb', line 174

def jobs # :nodoc:
  @jobs ||= Hash.new { |hash, key| hash[key] = [] }
end

Instance Method Details

#loggerObject



33
34
35
# File 'lib/sidekiq/worker.rb', line 33

def logger
  Sidekiq.logger
end