ActsAsAsync is an ActiveRecord extension that provides your models with easy-to-use Resque helpers.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

ActsAsAsync Build Status

ActsAsAsync is an ActiveRecord extension that provides your models with easy-to-use Resque helpers.


Installing ActsAsAsync is as simple as adding it to your Gemfile:

gem "acts_as_async"


ActsAsAsync aims to be as simple as possible to use. Including it in your model is as easy as:

class Post < ActiveRecord::Base

Basic usage

ActsAsAsync adds three instance methods to your model that you can use to async any other instance method:

post = Post.create(:body => "Wow, acts_as_async is neat!")

# Self-destruct as soon as possible

# Self-destruct at this time tomorrow
post.async_at( +, :destroy)

# Self-destruct in 10 minutes
post.async_in(10.minutes, :destroy)

It also adds three identical class methods:

Post.async_at(, :destroy_all)
Post.async_in(10.minutes, :destroy_all)

Dynamic methods

In addition to the helper methods above, ActsAsAsync supports dynamic methods for any existing method on your model. For example:

class Audiobook < ActiveRecord::Base

  def transcribe
	# Some long-running logic here

  def read!
	# Computers like to read too!

  def paint(color)
	# I don't know why you'd paint a book...

book = Audiobook.first

# Transcribe the book as soon as possible

# Read the book at this time tomorrow
book.async_read_at!( +

# Paint the book blue in a couple years
book.async_paint_in(2.years, "blue")

Additional notes

  • You can pass any number of additional arguments to async'd methods so long as they can be serialized into JSON
  • Adding acts_as_async to your Gemfile automatically loads both Resque and Resque-scheduler's rake tasks. This means you can use both $ rake resque:work and $ rake resque:scheduler right out of the box.
  • By deafult, each model will add tasks to a queue named "default". You can pass the :queue option to acts_as_async to specify a different queue.
  • Dynamic methods support names with exclamation points but not question marks. This was a design decision to discourage misuse of the question mark in method names. If you absolutely must async a method with a question mark, just use one of the async :method helpers.

Everything else...

ActsAsAsync is simply a thin layer on top of Resque and Resque-scheduler. To learn how to configure your redis connection, run workers, view the web interface, and more visit their home pages.


ActsAsAsync is tested against the following Rubies: MRI 1.8.7, MRI 1.9.2, MRI 1.9.3, Rubinius 2.0, and JRuby.


ActsAsAsync is released under the MIT license. See the LICENSE file for more info.