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 Classes: Setter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Trackable

#track_progress

Instance Attribute Details

#bidObject

Returns the value of attribute bid.



25
26
27
# File 'lib/faktory/job.rb', line 25

def bid
  @bid
end

#jidObject

Returns the value of attribute jid.



24
25
26
# File 'lib/faktory/job.rb', line 24

def jid
  @jid
end

Class Method Details

.clear_allObject

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_allObject

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

Raises:

  • (ArgumentError)


29
30
31
32
33
34
# File 'lib/faktory/job.rb', line 29

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

.jobsObject

:nodoc:



310
311
312
# File 'lib/faktory/testing.rb', line 310

def jobs # :nodoc:
  Queues.jobs_by_queue.values.flatten
end

.set(options) ⇒ Object



36
37
38
# File 'lib/faktory/job.rb', line 36

def self.set(options)
  Setter.new(options)
end

Instance Method Details

#batchObject



40
41
42
43
44
# File 'lib/faktory/job.rb', line 40

def batch
  if bid
    @batch ||= Faktory::Batch.new(bid)
  end
end

#loggerObject



46
47
48
# File 'lib/faktory/job.rb', line 46

def logger
  Faktory.logger
end