Fetching contributors…
Cannot retrieve contributors at this time
50 lines (32 sloc) 1.86 KB

Advanced Setup

Using ActiveRecord Without Rails

If you're using both Rails and ActiveRecord, the README describes how to get started with Que (which is pretty straightforward, since it includes a Railtie that handles a lot of setup for you). Otherwise, you'll need to do some manual setup.

If you're using ActiveRecord outside of Rails, you'll need to tell Que to piggyback on its connection pool after you've connected to the database:


require 'que'
Que.connection = ActiveRecord

Then you can queue jobs just as you would in Rails:

ActiveRecord::Base.transaction do
  @user = User.create(params[:user])
  SendRegistrationEmail.enqueue user_id:

There are other docs to read if you're using Sequel or plain Postgres connections (with no ORM at all) instead of ActiveRecord.

Managing the Jobs Table

After you've connected Que to the database, you can manage the jobs table. You'll want to migrate to a specific version in a migration file, to ensure that they work the same way even when you upgrade Que in the future:

# Update the schema to version #4.
Que.migrate! version: 4

# Remove Que's jobs table entirely.
Que.migrate! version: 0

There's also a helper method to clear all jobs from the jobs table:


Other Setup

Be sure to read the docs on managing workers for more information on using the worker pool.

You'll also want to set up logging and an error handler to track errors raised by jobs.