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
98 99 100 |
# File 'lib/sidekiq/testing.rb', line 98 def clear_all jobs.clear end |
.drain_all ⇒ Object
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 |
.jobs ⇒ Object
:nodoc:
93 94 95 |
# File 'lib/sidekiq/testing.rb', line 93 def jobs # :nodoc: @jobs ||= Hash.new { |hash, key| hash[key] = [] } end |