diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 32 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | Rakefile | 4 | ||||
-rw-r--r-- | lib/active_job/base.rb | 2 | ||||
-rw-r--r-- | lib/active_job/queue_adapters/qu_adapter.rb | 28 | ||||
-rw-r--r-- | lib/active_job/queue_name.rb | 16 | ||||
-rw-r--r-- | test/adapters/qu.rb | 3 | ||||
-rw-r--r-- | test/cases/adapter_test.rb | 5 | ||||
-rw-r--r-- | test/cases/queue_naming_test.rb | 6 |
10 files changed, 94 insertions, 11 deletions
@@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 7dda62c1fe..7dac1c6e88 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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: @@ -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'] diff --git a/lib/active_job/base.rb b/lib/active_job/base.rb index 0c772e3126..d5ba253016 100644 --- a/lib/active_job/base.rb +++ b/lib/active_job/base.rb @@ -9,8 +9,8 @@ require 'active_job/logging' module ActiveJob class Base extend QueueAdapter - extend QueueName + include QueueName include Enqueuing include Execution include Callbacks diff --git a/lib/active_job/queue_adapters/qu_adapter.rb b/lib/active_job/queue_adapters/qu_adapter.rb new file mode 100644 index 0000000000..7e69229801 --- /dev/null +++ b/lib/active_job/queue_adapters/qu_adapter.rb @@ -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 diff --git a/lib/active_job/queue_name.rb b/lib/active_job/queue_name.rb index a606b67370..859ddad034 100644 --- a/lib/active_job/queue_name.rb +++ b/lib/active_job/queue_name.rb @@ -1,10 +1,18 @@ module ActiveJob module QueueName - mattr_accessor(:queue_base_name) { "active_jobs" } - mattr_accessor(:queue_name) { queue_base_name } + extend ActiveSupport::Concern - def queue_as(part_name) - self.queue_name = "#{queue_base_name}_#{part_name}" + module ClassMethods + mattr_accessor(:queue_base_name) { "active_jobs" } + + def queue_as(part_name) + self.queue_name = "#{queue_base_name}_#{part_name}" + end + end + + included do + class_attribute :queue_name + self.queue_name = queue_base_name end end end
\ No newline at end of file diff --git a/test/adapters/qu.rb b/test/adapters/qu.rb new file mode 100644 index 0000000000..7728c843b4 --- /dev/null +++ b/test/adapters/qu.rb @@ -0,0 +1,3 @@ +require 'qu-immediate' + +ActiveJob::Base.queue_adapter = :qu diff --git a/test/cases/adapter_test.rb b/test/cases/adapter_test.rb index 703058dacb..7f6f4c1159 100644 --- a/test/cases/adapter_test.rb +++ b/test/cases/adapter_test.rb @@ -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 diff --git a/test/cases/queue_naming_test.rb b/test/cases/queue_naming_test.rb index e171474686..852643b9f6 100644 --- a/test/cases/queue_naming_test.rb +++ b/test/cases/queue_naming_test.rb @@ -9,9 +9,13 @@ class QueueNamingTest < ActiveSupport::TestCase test 'name appended in job' do begin HelloJob.queue_as :greetings + LoggingJob.queue_as :bookkeeping + + assert_equal "active_jobs", NestedJob.queue_name assert_equal "active_jobs_greetings", HelloJob.queue_name + assert_equal "active_jobs_bookkeeping", LoggingJob.queue_name ensure - HelloJob.queue_name = HelloJob.queue_base_name + HelloJob.queue_name = LoggingJob.queue_name = ActiveJob::Base.queue_base_name end end end |