• Stars
    star
    506
  • Rank 87,236 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 13 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a Ruby library for queuing and processing background jobs.

Qu

Qu is a Ruby library for queuing and processing background jobs. It is heavily inspired by delayed_job and Resque.

Qu was created to overcome some shortcomings in the existing queuing libraries that we experienced at Ordered List while building SpeakerDeck, Gaug.es and Harmony. The advantages of Qu are:

  • Multiple backends (redis, mongo)
  • Jobs are requeued when worker is killed
  • Resque-like API

Information & Help

  • Find more information on the Wiki.
  • Post to the Google Group for help or questions.
  • See the issue tracker for known issues or to report an issue.

Installation

Rails 3 and 4

Decide which backend you want to use and add the gem to your Gemfile.

gem 'qu-rails'
gem 'qu-redis'

That's all you need to do!

Rails 2

Decide which backend you want to use and add the gem to config.gems in environment.rb:

config.gem 'qu-redis'

To load the rake tasks, add the following to your Rakefile:

require 'qu/tasks'

Usage

Jobs are defined by extending the Qu::Job class:

class ProcessPresentation < Qu::Job
  def initialize(presentation_id)
    @presentation_id = presentation_id
  end

  def perform
    Presentation.find(@presentation_id).process!
  end
end

You can add a job to the queue by calling create on your job:

job = ProcessPresentation.create(@presentation.id)
puts "Created job #{job.id}"

The job will be initialized with any parameters that are passed to it when it is performed. These parameters will be stored in the backend, so they must be simple types that can easily be serialized and unserialized. Don't try to pass in an ActiveRecord object.

Processing the jobs on the queue can be done with a Rake task:

$ bundle exec rake qu:work

You can easily inspect the queue or clear it:

puts "Jobs on the queue:", Qu.size
Qu.clear

Queues

The default queue is used, um…by default. Jobs that don't specify a queue will be placed in that queue, and workers that don't specify a queue will work on that queue.

However, if you have some background jobs that are more or less important, or some that take longer than others, you may want to consider using multiple queues. You can have workers dedicated to specific queues, or simply tell all your workers to work on the most important queue first.

Jobs can be placed in a specific queue by setting the queue:

class CallThePresident < Qu::Job
  queue :urgent

  def initialize(message)
    @message = message
  end

  def perform
    # …
  end
end

You can then tell workers to work on this queue by passing an environment variable

$ bundle exec rake qu:work QUEUES=urgent,default

Note that if you still want your worker to process the default queue, you must specify it. Queues will be process in the order they are specified.

You can also get the size or clear a specific queue:

Qu.size(:urgent)
Qu.clear(:urgent)

Configuration

Most of the configuration for Qu should be automatic. It will also automatically detect ENV variables from Heroku for backend connections, so you shouldn't need to do anything to configure the backend.

However, if you do need to customize it, you can by calling the Qu.configure:

Qu.configure do |c|
  c.logger = Logger.new('log/qu.log')
  c.graceful_shutdown = true
end

Tests

If you prefer to have jobs processed immediatly in your tests, there is an Immediate backend that will perform the job instead of enqueuing it. In your test helper, require qu-immediate:

require 'qu-immediate'

Why another queuing library?

Resque and delayed_job are both great, but both of them have shortcomings that can be frustrating in production applications.

delayed_job was a brilliantly simple pioneer in the world of database-backed queues. While most asynchronous queuing systems were tending toward overly complex, it made use of your existing database and just worked. But there are a few flaws:

  • Occasionally fails silently.
  • Use of priority instead of separate named queues.
  • Contention in the ActiveRecord backend with multiple workers. Occasionally the same job gets performed by multiple workers.

Resque, the wiser relative of delayed_job, fixes most of those issues. But in doing so, it forces some of its beliefs on you, and sometimes those beliefs just don't make sense for your environment. Here are some of the flaws of Resque:

  • Redis is a great queue backend, but it doesn't make sense for every environment.
  • Forking before each job prevents memory leaks, but it is terribly inefficient in environments with a lot of fast jobs (the resque-jobs-per-fork plugin alleviates this)

Those shortcomings lead us to write Qu. It is not perfect, but we hope to overcome the issues we faced with other queuing libraries.

Contributing

If you find what looks like a bug:

  1. Search the issues on GitHub to see if anyone else has reported issue.
  2. If you don't see anything, create an issue with information on how to reproduce it.

If you want to contribute an enhancement or a fix:

  1. Fork the project on GitHub.
  2. Make your changes with tests.
  3. Commit the changes without making changes to the Rakefile, Gemfile, gemspec, or any other files that aren't related to your enhancement or fix
  4. Send a pull request.

More Repositories

1

dotenv

A Ruby gem to load environment variables from `.env`.
Ruby
6,388
star
2

gaskit

a git-backed issue tracker
JavaScript
903
star
3

stop-trump

a list of public projects on GitHub resisting the Trump administration
265
star
4

github-notifications

A client for reading GitHub notifications
CoffeeScript
212
star
5

morphine

a lightweight dependency injection framework for Ruby
Ruby
143
star
6

dotenv-deployment

Make dotenv more useful in other environments.
Ruby
97
star
7

strappydoo

bootstrap and run any project with the same command
Shell
77
star
8

github-app-example

JavaScript
70
star
9

OWNERS

a human and machine readable format that specifies who is responsible for maintaining a project
Ruby
66
star
10

workflow

GitHub workflow automation via .probot.js file in your repository.
JavaScript
47
star
11

adapter-git

Git adapter for adapter gem.
Ruby
42
star
12

chordpro

A ruby parser for the chordpro song file format.
Ruby
33
star
13

monologue

Sample application to demonstrate TDD and design patterns in JavaScript
JavaScript
24
star
14

chordbook

Chord sheets and tab for guitar and ukulele.
Ruby
23
star
15

parse-reminder

a node module to parse natural language reminders into who, what, and when
JavaScript
22
star
16

envy

a schema for your application's environment variables
Ruby
21
star
17

probot-owners

@mention maintainers in Pull Requests based on contents of the OWNERS file
JavaScript
21
star
18

spiderman

your friendly neighborhood web crawler
Ruby
18
star
19

annotation

Convert linter output into annotations for the GitHub Checks API
Go
11
star
20

update-dotenv

A NodeJS module to write updates to a .env file
JavaScript
10
star
21

sunspot_mongo_mapper

A Sunspot wrapper for MongoMapper.
Ruby
10
star
22

soapbox

a desktop application for presenting HTML-based slideshows
CoffeeScript
9
star
23

dashing-octostatus

GitHub Status widget for the dashing dashboard framework
CoffeeScript
9
star
24

lucid

JavaScript
8
star
25

chord-editor

Edit song sheets in ChordPro, Chord Sheet, and Ultimate Guitar formats
HTML
8
star
26

hubot-websocket

A websocket adapter for Hubot
CoffeeScript
8
star
27

webhook-proxy

JavaScript
8
star
28

tower_defense

A Tower Defense-style game written in Ruby with Gosu
Ruby
7
star
29

producingoss

Ruby
6
star
30

github-data

Interesting data about GitHub
5
star
31

dotfiles

Shell
5
star
32

bkeepers.github.io

CSS
5
star
33

talks

proposals, notes, and outlines for talks that I've written, submitted, or presented
4
star
34

retext-words

JavaScript
4
star
35

fsbo

Simple site to sell my house
JavaScript
4
star
36

state

a state machine for GitHub Issues and Pull Requests
JavaScript
4
star
37

atom

JavaScript
3
star
38

sanitize-whitelist

Ruby
3
star
39

readable.news

Social news made into a readable feed.
Vue
3
star
40

hubot-commands

experiment with building a command interface into Hubot
JavaScript
2
star
41

posthtml-extend-issues-28

HTML
2
star
42

heroku-buildpack-git-test

Shell
2
star
43

office

A place to talk with people about things.
2
star
44

git-history

article for .net Magazine
2
star
45

owners-node

JavaScript
2
star
46

mikedeboer.github.io

Website to redirect node-github
HTML
1
star
47

svada

JavaScript
1
star
48

markdown-test

1
star
49

hypester

Ruby
1
star
50

g2kg-intrawebs

Sample site for g2kg class
Ruby
1
star
51

github-for-developers-7

1
star
52

python-actions

GitHub Actions for Python packaging and distribution
Dockerfile
1
star
53

mailmerge

Ruby
1
star
54

testing

C
1
star
55

releaseactiontest

Ruby
1
star
56

github-notifications-app

A native wrapper around https://notifications.githubapp.com
JavaScript
1
star
57

expect-promise

an extension to expect for testing promises
JavaScript
1
star