提交 b36d4da3 编写于 作者: C Cristian Bica

Implemented :qu adapter

上级 694b5620
......@@ -12,3 +12,5 @@ gem 'queue_classic'
gem 'sneakers', '0.1.1.pre'
gem 'que'
gem 'backburner'
gem 'qu-rails', github: "bkeepers/qu", branch: "master"
gem 'qu-redis'
GIT
remote: git://github.com/bkeepers/qu.git
revision: 2175633a834504423368d71cb10fb9f072d76cd2
branch: master
specs:
qu (0.2.0)
qu-rails (0.2.0)
qu (= 0.2.0)
railties (>= 3.2, < 5)
qu-redis (0.2.0)
qu (= 0.2.0)
redis-namespace
PATH
remote: .
specs:
......@@ -8,6 +21,15 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actionpack (4.1.1)
actionview (= 4.1.1)
activesupport (= 4.1.1)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
actionview (4.1.1)
activesupport (= 4.1.1)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.1)
activesupport (= 4.1.1)
builder (~> 3.1)
......@@ -34,6 +56,7 @@ GEM
dante (0.1.5)
delayed_job (4.0.1)
activesupport (>= 3.0, < 4.2)
erubis (2.7.0)
i18n (0.6.9)
json (1.8.1)
minitest (5.3.4)
......@@ -46,6 +69,13 @@ GEM
rack (1.5.2)
rack-protection (1.5.2)
rack
rack-test (0.6.2)
rack (>= 1.0)
railties (4.1.1)
actionpack (= 4.1.1)
activesupport (= 4.1.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
redis (3.0.7)
redis-namespace (1.4.1)
......@@ -99,6 +129,8 @@ DEPENDENCIES
activejob!
backburner
delayed_job
qu-rails!
qu-redis
que
queue_classic
rake
......
......@@ -13,7 +13,7 @@ of the request-response cycle, so the user doesn't have to wait on it.
The main point is to ensure that all Rails apps will have a job infrastructure
in place, even if it's in the form of an "immediate runner". We can then have
framework features and other gems build on top of that, without having to worry
about API differences between Delayed Job and Resque. Picking your queuing
about API differences between Delayed Job and Resque. Picking your queuing
backend becomes more of an operational concern, then. And you'll be able to
switch between them without having to rewrite your jobs.
......@@ -24,7 +24,7 @@ Set the queue adapter for Active Job:
``` ruby
ActiveJob::Base.queue_adapter = :inline # default queue adapter
# Adapters currently supported: :backburner, :delayed_job, :que, :queue_classic,
# Adapters currently supported: :backburner, :delayed_job, :qu, :que, :queue_classic,
# :resque, :sidekiq, :sneakers, :sucker_punch
```
......@@ -44,7 +44,7 @@ Enqueue a job like so:
```ruby
MyJob.enqueue record # Enqueue a job to be performed as soon the queueing system is free.
```
```
```ruby
MyJob.enqueue_at Date.tomorrow.noon, record # Enqueue a job to be performed tomorrow at noon.
......@@ -92,6 +92,7 @@ We currently have adapters for:
* [Backburner](https://github.com/nesquena/backburner)
* [Delayed Job](https://github.com/collectiveidea/delayed_job)
* [Qu](https://github.com/bkeepers/qu)
* [Que](https://github.com/chanks/que)
* [QueueClassic](https://github.com/ryandotsmith/queue_classic)
* [Resque 1.x](https://github.com/resque/resque)
......
......@@ -20,11 +20,11 @@ task default: :test
desc 'Run all adapter tests'
task :test do
tasks = %w(test_inline test_delayed_job test_que test_queue_classic test_resque test_sidekiq test_sneakers test_sucker_punch test_backburner)
tasks = %w(test_inline test_delayed_job test_qu test_que test_queue_classic test_resque test_sidekiq test_sneakers test_sucker_punch test_backburner)
run_without_aborting(*tasks)
end
%w(inline delayed_job que queue_classic resque sidekiq sneakers sucker_punch backburner).each do |adapter|
%w(inline delayed_job qu que queue_classic resque sidekiq sneakers sucker_punch backburner).each do |adapter|
Rake::TestTask.new("test_#{adapter}") do |t|
t.libs << 'test'
t.test_files = FileList['test/cases/**/*_test.rb']
......
require 'qu'
module ActiveJob
module QueueAdapters
class QuAdapter
class << self
def enqueue(job, *args)
Qu::Payload.new(klass: JobWrapper, args: [job, *args], queue: job.queue_name).push
end
def enqueue_at(job, timestamp, *args)
raise NotImplementedError
end
end
class JobWrapper < Qu::Job
def initialize(job, *args)
@job = job
@args = args
end
def perform
@job.new.execute *@args
end
end
end
end
end
require 'qu-immediate'
ActiveJob::Base.queue_adapter = :qu
......@@ -14,6 +14,11 @@ class AdapterTest < ActiveSupport::TestCase
assert_equal ActiveJob::QueueAdapters::DelayedJobAdapter, ActiveJob::Base.queue_adapter
end
test 'should load Qu adapter' do
ActiveJob::Base.queue_adapter = :qu
assert_equal ActiveJob::QueueAdapters::QuAdapter, ActiveJob::Base.queue_adapter
end
test 'should load Que adapter' do
ActiveJob::Base.queue_adapter = :que
assert_equal ActiveJob::QueueAdapters::QueAdapter, ActiveJob::Base.queue_adapter
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册