A simple interface over several background job libraries like Resque, Sidekiq and DelayedJob.
Switch branches/tags
Pull request Compare This branch is 42 commits behind fnando:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib
spec
.gitignore
.rspec
Gemfile
Gemfile.lock
README.md
Rakefile
qe.gemspec

README.md

Qe

A simple interface over several background job libraries like Resque, Sidekiq and DelayedJob.

Usage

In this wild world where a new asynchronous job processing library is released every once in a while, Qe tries to keep a unified interface that works with the most famous libraries:

To set the adapter, just load the file according to your adapter:

require "qe/resque"
require "qe/qu"
require "qe/delayed_job"
require "qe/beanstalk"

You also need to require the library you're going to use. If you're using Rails with Bundler, you can simple require the correct file and dependency.

source :rubygems
gem "rails", "3.2.8"

gem "sidekiq"
gem "qe", :require => "qe/sidekiq"

gem "resque"
gem "qe", :require => "qe/resque"

gem "qu"
gem "qe", :require => "qe/qu"

gem "backburner"
gem "qe", :require => "qe/beanstalk"

Create a worker that will send e-mails through ActionMailer.

class MailerWorker
  include Qe::Worker

  def perform
    Mailer.public_send(options[:mail], options).deliver
  end
end

Define our Mailer class.

class Mailer < ActionMailer::Base
  def welcome(options)
    @options = options
    mail :to => options[:email]
  end
end

Enqueue a job to be processed asynchronously.

MailerWorker.enqueue({
  :mail => :welcome,
  :email => "john@example.org",
  :name => "John Doe"
})

Development support

Qe comes with development support. Instead of starting up workers on development environment, you can use the Qe::Immediate adapter, which executes your worker right away!

Qe.adapter = Qe::Immediate

If you're using Rails, you can add the line above to your config/environments/development.rb file.

Testing support

Qe also comes with testing support. Just require the qe/testing.rb file and a fake queuing adapter will be used. All enqueued jobs will be stored at Qe.jobs. Note that this method is only available on testing mode.

require "qe/testing"
Qe.adapter = Qe::Testing

If you"re using RSpec, you can require the qe/testing/rspec.rb file instead. This will reset Qe.jobs before every spec and will add a enqueue matcher.

# Add the following like to your spec_helper.rb file
require "qe/testing/rspec"

describe "Enqueuing a job" do
  it "enqueues job" do
    expect {
      # do something
    }.to enqueue(MailerWorker).with(:email => "john@example.org")
  end
end

Maintainer

License:

(The MIT License)

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.