Class: DelayedMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/delayed-method.rb

Class Method Summary collapse

Class Method Details

.enqueue(object, method, *args) ⇒ Object



17
18
19
20
21
# File 'lib/delayed-method.rb', line 17

def enqueue(object, method, *args)
  ensure_proper_call(object, method) do |klass, id|
    Resque.enqueue(DelayedMethod, klass, id, method, *args)
  end
end

.enqueue_at(time, object, method, *args) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/delayed-method.rb', line 30

def enqueue_at(time, object, method, *args)
  ensure_proper_call(object, method) do |klass, id|
    if Resque.respond_to?(:enqueue_at)
      Resque.enqueue_at(time, DelayedMethod, klass, id, method, *args)
    else
      raise "resque-scheduler need to be included for this to work"
    end
  end
end

.enqueue_to(queue, object, method, *args) ⇒ Object



23
24
25
26
27
# File 'lib/delayed-method.rb', line 23

def enqueue_to(queue, object, method, *args)
  ensure_proper_call(object, method) do |klass, id|
    Resque.enqueue_to(queue, DelayedMethod, klass, id, method, *args)
  end
end

.perform(klass_name, instance_id, method, *args) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/delayed-method.rb', line 8

def perform(klass_name, instance_id, method, *args)
  puts "<#{klass_name}##{instance_id}>##{method}#{args}"
  if instance_id
    Object.const_get(klass_name).find(instance_id).send(method, *args)
  else
    Object.const_get(klass_name).send(method, *args)
  end
end