Do things later with queue_classic
Ruby
Permalink
Failed to load latest commit information.
lib bump to 0.4.0.beta Aug 22, 2014
.gitignore Initial. Sep 28, 2012
Gemfile Initial. Sep 28, 2012
LICENSE.txt Initial. Sep 28, 2012
README.md now part of queue_classic core starting with 3.1 Jan 7, 2015
Rakefile Initial. Sep 28, 2012
queue_classic-later.gemspec change QC version to 3.0 stable Aug 22, 2014

README.md

QC::Later

Do things later with queue_classic.

IMPORTANT: this functionality is built in queue_classic starting with 3.1.

IMPORTANT: this branch is for QueueClassic 3. See the 0.3-stable branch for prior version support.

Installation

Add this line to your application's Gemfile:

gem "queue_classic-later"

And then execute:

$ bundle

Or install it yourself as:

$ gem install queue_classic-later

Setup

First, follow the queue_classic setup directions.

NOTE for Ruby 1.8.7: You'll also need to install the json gem--but you really should upgrade to a newer version of ruby, it's no longer being maintained.

QC::Later has database setup to do, much like queue_classic itself. Use the same process suggested by the queue_classic directions to run QC::Later::Setup.create in a database migration or similar.

You'll need to periodically call QC::Later.tick, such as via a clock process. Calling it every 5-10 seconds is probably sufficient.

Usage

QC::Later adds two methods to QC::Queue:

  • enqueue_in(seconds, method, *args): Like enqueue, but wait seconds before enqueueing the work
  • enqueue_at(time, method, *args): Like enqueue_in, but wait until time before enqueueing the work

Here's an example:

# Enqueue this in 30 seconds
QC.enqueue_in(30, "Kernel.puts", "hello world")

# Enqueue this at a specific time
QC.enqueue_at(Time.new(2012, 10, 13, 12, 34, 56), "Kernel.puts", "hello world")

QC::Later.tick will enqueue these jobs to be worked by your worker(s) at the appropriate time.

Credit

Heavily inspired by resque-scheduler.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request