Module: ActsAsAsync::Helper::ClassMethods

Defined in:
lib/acts_as_async/helper.rb

Instance Method Summary collapse

Instance Method Details

#async(method, *args) ⇒ Object



28
29
30
# File 'lib/acts_as_async/helper.rb', line 28

def async(method, *args)
  Resque.enqueue(self, method, *args)
end

#async_at(time, method, *args) ⇒ Object



32
33
34
# File 'lib/acts_as_async/helper.rb', line 32

def async_at(time, method, *args)
  Resque.enqueue_at(time, self, method, *args)
end

#async_in(time, method, *args) ⇒ Object



36
37
38
# File 'lib/acts_as_async/helper.rb', line 36

def async_in(time, method, *args)
  Resque.enqueue_in(time, self, method, *args)
end

#inherited(subclass) ⇒ Object



40
41
42
43
44
# File 'lib/acts_as_async/helper.rb', line 40

def inherited(subclass)
  queue = instance_variable_get(:@queue)
  subclass.instance_variable_set(:@queue, queue)
  super
end

#perform(*args) ⇒ Object

Args will be an optional ID, a method name and optional arguments



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/acts_as_async/helper.rb', line 12

def perform(*args)
  # Class methods
  if args.first.is_a? String
    receiver = self
    method = args.shift

  # Instance methods
  else
    id = args.shift
    receiver = find(id)
    method = args.shift
  end

  receiver.__send__(method, *args)
end