Module: Faktory::Job
- Includes:
- Trackable
- 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, Util Classes: Setter
Instance Attribute Summary collapse
-
#_custom ⇒ Object
Returns the value of attribute _custom.
-
#bid ⇒ Object
Returns the value of attribute bid.
-
#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:.
- .set(options) ⇒ Object
Instance Method Summary collapse
-
#batch ⇒ Object
this method is typically called within a batch job to reopen the batch in order to add more jobs.
- #logger ⇒ Object
-
#parent_batch ⇒ Object
this method is typically called within a child batch callback to reopen the parent batch in order to add more jobs or workflow steps.
- #parent_bid ⇒ Object
Methods included from Trackable
Instance Attribute Details
#_custom ⇒ Object
Returns the value of attribute _custom.
26 27 28 |
# File 'lib/faktory/job.rb', line 26 def _custom @_custom end |
#bid ⇒ Object
Returns the value of attribute bid.
25 26 27 |
# File 'lib/faktory/job.rb', line 25 def bid @bid end |
#jid ⇒ Object
Returns the value of attribute jid.
24 25 26 |
# File 'lib/faktory/job.rb', line 24 def jid @jid end |
Class Method Details
.clear_all ⇒ Object
Clear all queued jobs across all workers
314 315 316 |
# File 'lib/faktory/testing.rb', line 314 def clear_all Queues.clear_all end |
.drain_all ⇒ Object
Drain all queued jobs across all workers
319 320 321 322 323 324 325 326 327 |
# File 'lib/faktory/testing.rb', line 319 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
30 31 32 33 34 35 |
# File 'lib/faktory/job.rb', line 30 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:
309 310 311 |
# File 'lib/faktory/testing.rb', line 309 def jobs # :nodoc: Queues.jobs_by_queue.values.flatten end |
Instance Method Details
#batch ⇒ Object
this method is typically called within a batch job to reopen the batch in order to add more jobs.
43 44 45 46 47 |
# File 'lib/faktory/job.rb', line 43 def batch if bid @batch ||= Faktory::Batch.new(bid) end end |
#parent_batch ⇒ Object
this method is typically called within a child batch callback to reopen the parent batch in order to add more jobs or workflow steps.
51 52 53 54 55 |
# File 'lib/faktory/job.rb', line 51 def parent_batch if parent_bid @parent_batch ||= Faktory::Batch.new(parent_bid) end end |
#parent_bid ⇒ Object
57 58 59 |
# File 'lib/faktory/job.rb', line 57 def parent_bid _custom["_pbid"] end |