Skip to content

Commit

Permalink
Merge pull request #86 from cristianbica/qu_adapter
Browse files Browse the repository at this point in the history
Implemented :qu adapter
  • Loading branch information
dhh committed Jun 12, 2014
2 parents 694b562 + b36d4da commit 62c5ea5
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
32 changes: 32 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -99,6 +129,8 @@ DEPENDENCIES
activejob!
backburner
delayed_job
qu-rails!
qu-redis
que
queue_classic
rake
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
```

Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
28 changes: 28 additions & 0 deletions lib/active_job/queue_adapters/qu_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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
3 changes: 3 additions & 0 deletions test/adapters/qu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'qu-immediate'

ActiveJob::Base.queue_adapter = :qu
5 changes: 5 additions & 0 deletions test/cases/adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 62c5ea5

Please sign in to comment.