Module: Sidekiq::Job
- Included in:
- ActiveJob::Wrapper
- Defined in:
- lib/sidekiq/job.rb,
lib/sidekiq/testing.rb,
lib/sidekiq/job/iterable.rb,
lib/sidekiq/job/interrupt_handler.rb,
lib/sidekiq/job/iterable/enumerators.rb,
lib/sidekiq/job/iterable/csv_enumerator.rb,
lib/sidekiq/job/iterable/active_record_enumerator.rb
Overview
Include this module in your job class and you can easily create asynchronous jobs:
class HardJob
include Sidekiq::Job
queue: 'critical', retry: 5
def perform(*args)
# do some work
end
end
Then in your Rails app, you can do this:
HardJob.perform_async(1, 2, 3)
Note that perform_async is a class method, perform is an instance method.
Sidekiq::Job also includes several APIs to provide compatibility with ActiveJob.
class SomeJob
include Sidekiq::Job
queue_as :critical
def perform(...)
end
end
SomeJob.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, Iterable, Options Classes: InterruptHandler, Interrupted, Setter
Instance Attribute Summary collapse
-
#_context ⇒ Object
This attribute is implementation-specific and not a public API.
-
#jid ⇒ Object
Returns the value of attribute jid.
Class Method Summary collapse
-
.clear_all ⇒ Object
Clear all queued jobs.
-
.drain_all ⇒ Object
Drain (execute) all queued jobs.
- .included(base) ⇒ Object
-
.jobs ⇒ Object
:nodoc:.
Instance Method Summary collapse
Instance Attribute Details
#_context ⇒ Object
This attribute is implementation-specific and not a public API
163 164 165 |
# File 'lib/sidekiq/job.rb', line 163 def _context @_context end |
#jid ⇒ Object
Returns the value of attribute jid.
160 161 162 |
# File 'lib/sidekiq/job.rb', line 160 def jid @jid end |
Class Method Details
.clear_all ⇒ Object
Clear all queued jobs
305 306 307 |
# File 'lib/sidekiq/testing.rb', line 305 def clear_all Queues.clear_all end |
.drain_all ⇒ Object
Drain (execute) all queued jobs
310 311 312 313 314 315 316 317 318 |
# File 'lib/sidekiq/testing.rb', line 310 def drain_all while jobs.any? job_classes = jobs.map { |job| job["class"] }.uniq job_classes.each do |job_class| Object.const_get(job_class).drain end end end |
.included(base) ⇒ Object
165 166 167 168 169 170 |
# File 'lib/sidekiq/job.rb', line 165 def self.included(base) raise ArgumentError, "Sidekiq::Job cannot be included in an ActiveJob: #{base.name}" if base.ancestors.any? { |c| c.name == "ActiveJob::Base" } base.include(Options) base.extend(ClassMethods) end |
.jobs ⇒ Object
:nodoc:
300 301 302 |
# File 'lib/sidekiq/testing.rb', line 300 def jobs # :nodoc: Queues.jobs_by_queue.values.flatten end |