Module: Resque::Mixin::Async

Defined in:
lib/resque/mixin/async.rb

Overview

Module that provides easy queueing of jobs. Transparently handles instance and class methods.

If you consider this class:

class Repository < ActiveRecord::Base
  include Resque::Mixin::Async
  @queue = :high_priority

  def self.create_index
    # code
  end

  def notify_watchers
    # code
  end
end

you can queue new jobs on both the class and an instance like this:

@repository.async(:notify_watchers)
Repository.async(:create_index)

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



27
28
29
# File 'lib/resque/mixin/async.rb', line 27

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

Instance Method Details

#async(method, *args) ⇒ Object



31
32
33
# File 'lib/resque/mixin/async.rb', line 31

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

#async_in_queue(run_queue, method, *args) ⇒ Object



35
36
37
38
39
40
# File 'lib/resque/mixin/async.rb', line 35

def async_in_queue(run_queue, method, *args)
  orig_queue = self.class.queue
  self.class.queue = run_queue
  Resque.enqueue(self.class, id, method, *args)
  self.class.queue = orig_queue
end