Skip to content


Subversion checkout URL

You can clone with
Download ZIP
ActsAsAsync is an ActiveRecord extension that provides your models with easy-to-use Resque helpers.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib Bump to v0.3.0
spec Properly tests #async_at and #async_in (#8)
.gitignore Ignoring Gemfile.lock
.rspec General cleanup, add rpsec, add dynamic methods
.travis.yml Updates travis
Gemfile Updates test dependencies
LICENSE Wrote a real README Removes gemnasium image
Rakefile Shouldn't need sudo to install gem from Rakefile
acts_as_async.gemspec Started implemented specs. Got AR set up

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.

Something went wrong with that request. Please try again.