Getting started with QueueClassic
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?
transaction.do # do stuff enqueue_some_email("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!
How to start using it, TODAY
You have a Ruby app and PostgreSQL? You’ve got everything you need!
Add this to your Gemfile:
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!
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:
QC.enqueue("Kernel.puts", "Rainforest QA is amazing!")
In real life, you are most likely to create dedicated classes, but you get the point!
By default, it will create a new database connection. If you want to share your ActiveRecord connection, just add this to an initializer:
QC.default_conn_adapter = 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!Learn more about Rainforest