simple background execution of model methods
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
bin use rspec for testsuite Dec 23, 2015
lib bump version Aug 29, 2016
spec Remove Rails Dependency Issues Aug 26, 2016
.rvmrc loosen ruby requirement Mar 20, 2013
.travis.yml use rspec for testsuite Dec 23, 2015
Gemfile use bundler Jun 2, 2011
LICENSE Initial commit to background_model. Jun 30, 2009 use rspec for testsuite Dec 23, 2015
Rakefile convert to rspec Dec 23, 2015

Build Status


The cleanest way to integrate background processing into your application.

Backgrounded provides a thin wrapper around any background processing framework that implements the Backgrounded handler API which makes it trivial to swap out processing frameworks with no impact to your code.


  • clean and concise API which removes any dependency on external “worker” jobs and allows you to execute any model method in the background
  • integrates with any background processing framework (DelayedJob, Resque, JobFu, Workling, etc)
  • background methods can be actually unit tested by using an "in process" runner
  • custom callbacks to execute ActiveRecord callbacks in the background after being committed to the database

General Usage

class User
  def do_stuff
  def self.do_something_else

user =
# execute instance method in background

# execute class method in background

after_commit_backgrounded Callback

Automatically execute a callback in the background after a model has been saved to the database. All of the standard after_commit options are available as well as an optional :backgrounded option which will be passed to the Backgrounded::Handler.

class User < ActiveRecord::Base
  # execute :do_something in the background after committed
  after_commit_backgrounded :do_something

  # execute :do_something_else in the background after committed
  # passing custom options to the backgrounded handler
  after_commit_backgrounded :do_something_else, :backgrounded => {:priority => :high}


$ gem install backgrounded


Backgrounded handlers are available for popular libraries in separate gems. Just drop in the gem for your particular framework or write your own!





Custom Handlers

Writing a custom handler is as simple as:

# config/initializers/backgrounded.rb
class MyHandler
  # @param object is the target object to invoke the method upon
  # @param method is the requested method to call
  # @param args is the optional list of arguments to pass to the method
  # @param options is the optional hash of options passed to the backgrounded call
  def request(object, method, args, options={})
    # process the call however you want!

# configure backgrounded to use your handler like so:
Backgrounded.configure do |config|
  config.handler =


Copyright © 2012 Ryan Sonnek. See LICENSE for details.