Module: SuckerPunch::Job

Defined in:
lib/sucker_punch/job.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 excuted 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

.included(base) ⇒ Object



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

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

  base.num_workers = 2
end

Instance Method Details

#asyncObject



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

def async
  AsyncProxy.new(self)
end

#loggerObject



28
29
30
# File 'lib/sucker_punch/job.rb', line 28

def logger
  SuckerPunch.logger
end