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



98
99
100
# File 'lib/sidekiq/testing.rb', line 98

def clear_all
  jobs.clear
end

.drain_allObject

Drain all queued jobs across all workers



103
104
105
106
107
# File 'lib/sidekiq/testing.rb', line 103

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

.included(base) ⇒ Object



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

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

.jobsObject

:nodoc:



93
94
95
# File 'lib/sidekiq/testing.rb', line 93

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

Instance Method Details

#loggerObject



31
32
33
# File 'lib/sidekiq/worker.rb', line 31

def logger
  Sidekiq.logger
end