Module: SuckerPunch::Job

Defined in:
lib/sucker_punch/job.rb,
lib/sucker_punch/testing.rb,
lib/sucker_punch/async_syntax.rb,
lib/sucker_punch/testing/inline.rb

Overview

Include this module in your job class to create asynchronous jobs:

class LogJob

include SuckerPunch::Job
workers 4

def perform(*args)
  # log the things
end

end

To trigger asynchronous job:

LogJob.perform_async(1, 2, 3)
LogJob.perform_in(60, 1, 2, 3) # `perform` will be executed 60 sec. later

Note that perform_async is a class method, perform is an instance method.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_allObject


27
28
29
# File 'lib/sucker_punch/testing.rb', line 27

def self.clear_all

end

.included(base) ⇒ Object


21
22
23
24
25
26
27
28
# File 'lib/sucker_punch/job.rb', line 21

def self.included(base)
  base.extend(ClassMethods)
  base.class_attribute :num_workers
  base.class_attribute :num_jobs_max

  base.num_workers = 2
  base.num_jobs_max = nil
end

.jobsObject


23
24
25
# File 'lib/sucker_punch/testing.rb', line 23

def self.jobs
  SuckerPunch::Queue.find_or_create(self.to_s)
end

Instance Method Details

#asyncObject


3
4
5
# File 'lib/sucker_punch/async_syntax.rb', line 3

def async
  AsyncProxy.new(self)
end

#loggerObject


30
31
32
# File 'lib/sucker_punch/job.rb', line 30

def logger
  SuckerPunch.logger
end