Module: Qe
- Defined in:
- lib/qe.rb,
lib/qe/qu.rb,
lib/qe/action.rb,
lib/qe/locale.rb,
lib/qe/resque.rb,
lib/qe/worker.rb,
lib/qe/sidekiq.rb,
lib/qe/testing.rb,
lib/qe/version.rb,
lib/qe/beanstalk.rb,
lib/qe/immediate.rb,
lib/qe/delayed_job.rb,
lib/qe/action_mailer.rb,
lib/qe/testing/rspec.rb,
lib/qe/worker/class_methods.rb,
lib/qe/worker/instance_methods.rb
Overview
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 most famous libraries:
# Sidekiq # Resque # DelayedJob # Qu # Beanstalk/Backburner
See an example:
You can choose an adapter:
Qe.adapter = Qe::Sidekiq
Qe.adapter = Qe::Resque
Qe.adapter = Qe::Qu
Qe.adapter = Qe::DelayedJob
Qe.adapter = Qe::Beanstalk
Create our worker that will send e-mails through ActionMailer
.
class MailerWorker
include Qe::Worker
def perform
Mailer.public_send([:mail], ).deliver
end
end
Define our Mailer
class.
class Mailer < ActionMailer::Base
def welcome()
=
mail :to => [:email]
end
end
Enqueue a job to be processed asynchronously.
MailerWorker.enqueue({
:mail => :welcome,
:email => "[email protected]",
:name => "John Doe"
})
You can specify when this job must be processed by setting the :run_at
option.
MailerWorker.enqueue({
:mail => :follow_up,
:email => "[email protected]",
:name => "John Doe",
:run_at => 5.days.from_now
})
Testing support
Qe 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.
require "qe/testing/rspec"
describe "Enqueuing a job" do
it "enqueues job" do
expect {
# do something
}.to enqueue(MailerWorker).with(:email => "[email protected]")
end
end
Defined Under Namespace
Modules: Action, ActionMailer, EnqueueMatcher, Locale, Worker Classes: Beanstalk, DelayedJob, Immediate, Qu, Resque, Sidekiq, Testing
Constant Summary collapse
- UnsupportedFeatureError =
Error that is raised when trying to use a feature that isn’t supported by some adapter.
Class.new(StandardError)
- OutOfOrderError =
Error that is raised when trying to include a module before Qe::Worker is included.
Class.new(StandardError)
- VERSION =
"0.4.0"
Class Attribute Summary collapse
-
.adapter ⇒ Object
Returns the value of attribute adapter.
Class Method Summary collapse
Class Attribute Details
.adapter ⇒ Object
Returns the value of attribute adapter.
94 95 96 |
# File 'lib/qe.rb', line 94 def adapter @adapter end |
Class Method Details
.drain ⇒ Object
6 7 8 9 10 |
# File 'lib/qe/testing.rb', line 6 def self.drain jobs.each do |job| Qe::Worker.perform(job[:worker].name, job[:options]) end end |
.jobs ⇒ Object
2 3 4 |
# File 'lib/qe/testing.rb', line 2 def self.jobs @jobs ||= [] end |