Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Background task handler based on spawn and delayed_job
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib I should also actually remove it ... *.*
spec Spec updates
README.rdoc Added spawn block in quick how-to
VERSION Version bump to 0.1.5
runner.gemspec Regenerated gemspec for version 0.1.5



Runner is a background task processor which is based on both spawn and delayed_job Unlike delayed_job, Runner doesn't need a separate rake task which runs your background tasks.


  • Easy way to implement other backends. Currently only supports ActiveRecord.

  • Convenient way to run methods as a separate process (see Quick-how-to).

  • Different concurrency methods supported (Forking, Threading and yielding)

  • Methods can be queued to be run at a later time giving you the option to run jobs at night by cron for example.

  • TaskSpawner which can be used to run queued tasks in the background.


You can use the latest Rails 3 gem with the latest Runner gem and include it in your Gemfile:

gem 'runner', :git => 'git://'

After you installed Runner thru bundler, you need to run the generator:

rails g runner

The runner generator generates a Migration file and an initializer file. If you use migrations please run:

rake db:migrate

Please refer to the Migration file if you rather set up your table your self.

Getting started

A Quick how to:

Running a task in the background is as easy as doing:


Instance methods are also supported:

klass =

If you wish you may also use blocks instead of methods for spawn

class Klass
  def my_method
    2 + 2
    spawn do
      # Execute this long running block in the background

And of course you can just pass options to the spawn block

spawn(:with => :thread) do
  # Execute

If you'd like to have an instance method always run in the background you could use the handle_asynch class method. This forces the method to be run in the background no matter what:

class MyClass
  def my_method
    2 + 2
  handle_asynch :my_method
c =; c.my_method # => my_method will run in the background.

If don't want your method to be run immediately you can choose to queue the call, which gives you the option to run it at a later time in the background:

Klass.spawn(:method => :queue).some_method_name

Somewhere else in your application you could start up a task spawner which runs all tasks which are currently queued for running:

c =

If you would like to overwrite the default concurrency method you could pass :with to spawn for non-queued processes:

Klass.spawn(:with => :thread).hello # => Forces the hello method to be executed in a thread rather than the default option.

For queued tasks you could force the TaskSpawner to use a specific concurrency method

Klass.spawn(:method => :queue, :with => :yield).some_method_name # => :with is ignored

Somewhere else in your application you could do:

c = => :fork)
c.start_handlers # => Forces all tasks to be forked

Please note that queued calls are subject to chance.

TODO Update this README file :)

Something went wrong with that request. Please try again.