Module: Sidekiq::Worker
- Defined in:
- lib/sidekiq/worker.rb
Overview
Include this module in your worker class and you can easily create asynchronous jobs:
class HardWorker
include Sidekiq::Worker
queue: 'critical', retry: 5
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.
Sidekiq::Worker also includes several APIs to provide compatibility with ActiveJob.
class SomeWorker
include Sidekiq::Worker
queue_as :critical
def perform(...)
end
end
SomeWorker.set(wait_until: 1.hour).perform_async(123)
Note that arguments passed to the job must still obey Sidekiq's best practice for simple, JSON-native data types. Sidekiq will not implement ActiveJob's more complex argument serialization. For this reason, we don't implement `perform_later` as our call semantics are very different.
Defined Under Namespace
Modules: ClassMethods, Options Classes: Setter
Instance Attribute Summary collapse
-
#jid ⇒ Object
Returns the value of attribute jid.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#jid ⇒ Object
Returns the value of attribute jid.
156 157 158 |
# File 'lib/sidekiq/worker.rb', line 156 def jid @jid end |
Class Method Details
.included(base) ⇒ Object
158 159 160 161 162 163 |
# File 'lib/sidekiq/worker.rb', line 158 def self.included(base) raise ArgumentError, "Sidekiq::Worker cannot be included in an ActiveJob: #{base.name}" if base.ancestors.any? { |c| c.name == "ActiveJob::Base" } base.include(Options) base.extend(ClassMethods) end |