Module: Backburner::Performable::ClassMethods

Defined in:
lib/backburner/performable.rb

Overview

InstanceMethods

Instance Method Summary collapse

Instance Method Details

#async(opts = {}) ⇒ Object

Return proxy object to enqueue jobs for object Options: ‘pri` (priority), `delay` (delay in secs), `ttr` (time to respond), `queue` (queue name)

Examples:

Model.async(:ttr => 300).do_something("foo")


25
26
27
# File 'lib/backburner/performable.rb', line 25

def async(opts={})
  Backburner::AsyncProxy.new(self, nil, opts)
end

#handle_asynchronously(method, opts = {}) ⇒ Object

Always handle an instance method asynchronously

Examples:

User.handle_asynchronously :send_welcome_email, queue: 'send-mail', delay: 10


43
44
45
# File 'lib/backburner/performable.rb', line 43

def handle_asynchronously(method, opts={})
  Backburner::Performable.handle_asynchronously(self, method, opts)
end

#handle_static_asynchronously(method, opts = {}) ⇒ Object

Always handle a class method asynchronously

Examples:

User.handle_static_asynchronously :update_recent_visitors, ttr: 300


50
51
52
# File 'lib/backburner/performable.rb', line 50

def handle_static_asynchronously(method, opts={})
  Backburner::Performable.handle_static_asynchronously(self, method, opts)
end

#perform(id, method, *args) ⇒ Object

Defines perform method for job processing

Examples:

perform(55, :do_something, "foo", "bar")


32
33
34
35
36
37
38
# File 'lib/backburner/performable.rb', line 32

def perform(id, method, *args)
  if id # instance
    find(id).send(method, *args)
  else # class method
    send(method, *args)
  end
end