Module: Faktory::Job
- Included in:
- ActiveJob::QueueAdapters::FaktoryAdapter::JobWrapper
- Defined in:
- lib/faktory/job.rb,
lib/faktory/testing.rb
Overview
Include this module in your Job class and you can easily create asynchronous jobs:
class HardJob
include Faktory::Job
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.
Defined Under Namespace
Modules: ClassMethods Classes: Setter
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.
22 23 24 |
# File 'lib/faktory/job.rb', line 22 def jid @jid end |
Class Method Details
.clear_all ⇒ Object
Clear all queued jobs across all workers
315 316 317 |
# File 'lib/faktory/testing.rb', line 315 def clear_all Queues.clear_all end |
.drain_all ⇒ Object
Drain all queued jobs across all workers
320 321 322 323 324 325 326 327 328 |
# File 'lib/faktory/testing.rb', line 320 def drain_all while jobs.any? worker_classes = jobs.map { |job| job["jobtype"] }.uniq worker_classes.each do |worker_class| Faktory::Testing.constantize(worker_class).drain end end end |
.included(base) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/faktory/job.rb', line 24 def self.included(base) raise ArgumentError, "You cannot include Faktory::Job in an ActiveJob: #{base.name}" if base.ancestors.any? {|c| c.name == 'ActiveJob::Base' } base.extend(ClassMethods) base.faktory_class_attribute :faktory_options_hash end |
.jobs ⇒ Object
:nodoc:
310 311 312 |
# File 'lib/faktory/testing.rb', line 310 def jobs # :nodoc: Queues.jobs_by_queue.values.flatten end |