Module: Resque::Plugins::SendLater

Defined in:
lib/resque/plugins/send_later.rb

Defined Under Namespace

Classes: DelayedPerformer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/resque/plugins/send_later.rb', line 8

def self.included(base)
  base.extend self
end

Instance Method Details

#handle_exception(ex, method, *args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/resque/plugins/send_later.rb', line 26

def handle_exception(ex, method, *args)
  # Try to spawn instead
  if defined? Spawn
    puts "transaction spawning due to exception #{ex.inspect} #{ex.backtrace.join("\n")}"
    spawn do
      self.send(method, *args)
    end
  else
    puts "no way to handle transaction with exception #{ex.inspect} #{ex.backtrace.join("\n")}"
  end
end

#send_later(method, *args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/resque/plugins/send_later.rb', line 12

def send_later(method, *args)
  if self.instance_of? Class
    classname = self.to_s
    refid = nil
  else
    classname = self.class.to_s
    refid = self.id
  end
  Resque.enqueue(Resque::Plugins::SendLater::DelayedPerformer, classname, refid, method, *args)
rescue Exception => ex
  handle_exception(ex, method, *args)
end