Module: Sidekiq::Worker
- 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
-
#jid ⇒ Object
Returns the value of attribute jid.
Class Method Summary collapse
-
.clear_all ⇒ Object
Clear all queued jobs across all workers.
-
.drain_all ⇒ Object
Drain all queued jobs across all workers.
- .included(base) ⇒ Object
-
.jobs ⇒ Object
:nodoc:.
Instance Method Summary collapse
Instance Attribute Details
#jid ⇒ Object
Returns the value of attribute jid.
24 25 26 |
# File 'lib/sidekiq/worker.rb', line 24 def jid @jid end |
Class Method Details
.clear_all ⇒ Object
Clear all queued jobs across all workers
181 182 183 |
# File 'lib/sidekiq/testing.rb', line 181 def clear_all jobs.clear end |
.drain_all ⇒ Object
Drain all queued jobs across all workers
186 187 188 189 190 |
# File 'lib/sidekiq/testing.rb', line 186 def drain_all until jobs.values.all?(&:empty?) do jobs.keys.each(&:drain) end end |
.included(base) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/sidekiq/worker.rb', line 26 def self.included(base) raise ArgumentError, "You cannot include Sidekiq::Worker in an ActiveJob: #{base.name}" if base.ancestors.any? {|c| c.name == 'ActiveJob::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 |
.jobs ⇒ Object
:nodoc:
176 177 178 |
# File 'lib/sidekiq/testing.rb', line 176 def jobs # :nodoc: @jobs ||= Hash.new { |hash, key| hash[key] = [] } end |