Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
Q

queue_classic

> 编程语言
Open source

Simple, efficient worker queue for Ruby & PostgreSQL.

1.2K stars0 likes2 views
WebsiteGitHub

About

Simple, efficient worker queue for Ruby & PostgreSQL.

queue_classic

A simple, efficient worker queue for Ruby & PostgreSQL.

Why this over something like Resque. Two reasons:

  1. Your jobs can be equeued in the same transaction as other modifications to the database, and will only be processed when everything is commited. This is a hard pattern to develop around for queues done outside your database
  2. Less things to run, if you don't already have Redis or a dedicated queue in your stack.

IMPORTANT NOTE: This README is representing the current work for queue_classic, which is generally the pending next version.

You can always find the latest and previous releases here:

https://github.com/QueueClassic/queue_classic/releases

Other related projects

If you're interested in this project, you might also want to checkout:

  • Que
  • GoodJob
  • Delayed Job

For a list of other queues (which may or may not be Postgres backed), checkout - https://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html

What is queue_classic?

queue_classic provides a simple interface to a PostgreSQL-backed message queue. queue_classic specializes in concurrent locking and minimizing database load while providing a simple, intuitive developer experience. queue_classic assumes that you are already using PostgreSQL in your production environment and that adding another dependency (e.g. redis, beanstalkd, 0mq) is undesirable.

A major benefit is the ability to enqueue inside transactions, ensuring things are done only when your changes are commited.

Other related projects

  • Queue Classic Plus - adds support for retrying with specific exceptions, transaction processing of jobs, metric collection, etc
  • Queue Classic Admin - Admin interface for queue_classic
  • Queue Classic Matchers - RSpec matchers for queue_classic

Features

  • Leverage of PostgreSQL's listen/notify, skip locked, and row locking.
  • Support for multiple queues with heterogeneous workers.
  • JSON data format.
  • Workers can work multiple queues.

Requirements

For this version, the requirements are as follows:

  • Ruby 3.0, 3.1, 3.2, 3.3 - i.e. currently supported non-EOL Ruby versions
  • Postgres ~> 9.6
  • Rubygem: pg ~> 1.1

Table of contents

  • Documentation
  • Usage
  • Setup
  • Upgrade from earlier versions to V3.1
  • Configuration
    • JSON
    • Logging
  • Support
  • Hacking
  • License

Usage

There are 2 ways to use queue_classic:

  • Producing Jobs
  • Working Jobs

Producing Jobs

Simple Enqueue

The first argument is a string which represents a ruby object and a method name. The second argument(s) will be passed along as arguments to the method defined by the first argument. The set of arguments will be encoded as JSON and stored in the database.

ruby
# This method has no arguments.
QC.enqueue("Time.now")

# This method has 1 argument.
QC.enqueue("Kernel.puts", "hello world")

# This method has 2 arguments.
QC.enqueue("Kernel.printf", "hello %s", "world")

# This method has a hash argument.
QC.enqueue("Kernel.puts", {"hello" => "world"})

# This method has an array argument.
QC.enqueue("Kernel.puts", ["hello", "world"])

# This method uses a non-default queue.
p_queue = QC::Queue.new("priority_queue")
p_queue.enqueue("Kernel.puts", ["hello", "world"])

Scheduling for later

There is also the ability to schedule a job to run at a specified time in the future. The job will become processable after the specified time, and will be processed as-soon-as-possible.

ruby
# Specify the job execution time exactly
QC.enqueue_at(Time.new(2024,01,02,10,00), "Kernel.puts", "hello future")

# Specify the job execution time as an offset in seconds
QC.enqueue_in(60, "Kernel.puts", "hello from 1 minute later")

Working Jobs

There are two ways to work/process jobs. The first approach is to use the Rake task. The second approach is to use a custom executable.

Rake Task

Require queue_classic in your Rakefile:

ruby
require 'queue_classic'
require 'queue_classic/tasks'
Work all queues

Start the worker via the Rakefile:

bash
bundle exec rake qc:work
Work a single specific queue

Setup a worker to work only a specific, non-default queue:

bash
QUEUE="priority_queue" bundle exec rake qc:work
Work multiple queues

In this scenario, on each iteration of the worker's loop, it will look for jobs in the first queue prior to looking at the second queue. This means that the first queue must be empty before the worker will look at the second queue.

bash
QUEUES="priority_queue,secondary_queue" bundle exec rake qc:work

Custom Worker

This example is probably not production ready; however, it serves as an example of how to leverage the code in the Worker class to fit your non-default requirements.

…

bash{:copy}

Creating the table and functions

bundle exec rake qc:create

Dropping the table and functions

bundle exec rake qc:drop

…

bash{:copy} rails generate queue_classic:install bundle exec rake db:migrate


### Rake Task
This rake task will update you to the latest version:

```bash{:copy}
# Updating the table and functions
bundle exec rake qc:update

Configuration

All configuration takes place in the form of environment vars. See queue_classic.rb for a list of options.

Logging

By default queue_classic does not talk very much. If you find yourself in a situation where you need to know what's happening inside QC, there are two different kind of logging you can enable: DEBUG and MEASURE.

Measure

This will output the time to process and some more statistics. To enable it, set the QC_MEASURE:

bash
export QC_MEASURE="true"

Debug

You can enable the debug output by setting the DEBUG environment variable:

bash
export DEBUG="true"

Support

If you think you have found a bug, feel free to open an issue. Use the following template for the new issue:

  1. List your versions: Ruby, PostgreSQL, queue_classic.
  2. Define what you would have expected to happen.
  3. List what actually happened.
  4. Provide sample codes & commands which will reproduce the problem.

Hacking on queue_classic

Running Tests

bash
bundle
createdb queue_classic_test
export QC_DATABASE_URL="postgres://username:pass@localhost/queue_classic_test"
bundle exec rake                      # run all tests
bundle exec ruby test/queue_test.rb   # run a single test

License

Copyright (C) 2010 Ryan Smith

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyactivejobqueuequeuing

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言