Any serious project nowadays needs background processing, right? Most of the Ruby community uses Sidekiq or Resque but there are other options. One is QueueClassic. QueueClassic uses PostgreSQL instead of Redis for Sidekiq.

Why should you use it?

Transactions: have you ever done this?

ruby transaction.do # do stuff enqueuesomeemail("Hi, we sent you...") # rollback end

Too late, your mail is sent...but wait: not with QueueClassic! It is all in PostgreSQL which makes it more flexible.

Less moving parts: you already use PostgreSQL? No need to add anything!

Finally, it has a small code base making it easy for you to jump in and add features on top of it.

You have a Ruby app and PostgreSQL? You've got everything you need!

Setup

Add this to your Gemfile:

ruby gem "queue_classic"

Run bundle install

If you use Rails, run:

rails generate queue_classic:install bundle exec rake db:migrate

If you are NOT using Rails, run:

bundle exec rake qc:create

You will probably have to add require 'queue_classic' somewhere in your project.

Run a worker

Out of the box, the worker will run on the "default" queue. If you want to use the default, you only have to run:

bundle exec rake qc:work

That's it, you are ready to enqueue and process tons of jobs!

Enqueue jobs

One of the fun things with QueueClassic is that you don't have to create dedicated class with a specific structure or include any magic sauce, you can enqueue anything you want! Example:

ruby QC.enqueue("Kernel.puts", "Rainforest QA is amazing!")

In real life, you are most likely to create dedicated classes, but you get the point!

Little trick

By default, it will create a new database connection. If you want to share your ActiveRecord connection, just add this to an initializer:

ruby QC.defaultconnadapter = QC::ConnAdapter.new(ActiveRecord::Base.connection.raw_connection)

Now that you are ready to enqueue jobs like crazy, what's next?

Here is a list of tools that were built on top of QueueClassic:

queue_classic_admin: An admin interface for QueueClassic, built by our very own Simon.

queue_classic-later: Do things later with queue_classic.

qc-mailer: Send email in the background using QueueClassic.

Play with it and feel the simplicity!