aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Bica <cristian.bica@gmail.com>2014-05-20 00:01:56 +0300
committerCristian Bica <cristian.bica@gmail.com>2014-05-20 00:01:56 +0300
commit5cad2c1b8aa1139ba3de45b3ce26b9d5c9931f6c (patch)
tree63fd313e325270847760c81e82369d9286a57f5e
parentac930b8077a7f494d531b9bb34aa431870fb0a3f (diff)
downloadrails-5cad2c1b8aa1139ba3de45b3ce26b9d5c9931f6c.tar.gz
rails-5cad2c1b8aa1139ba3de45b3ce26b9d5c9931f6c.tar.bz2
rails-5cad2c1b8aa1139ba3de45b3ce26b9d5c9931f6c.zip
Implemented queue_classic adapter
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock4
-rw-r--r--README.md4
-rw-r--r--Rakefile4
-rw-r--r--lib/active_job/queue_adapters/queue_classic_adapter.rb20
-rw-r--r--test/adapters/queue_classic.rb2
-rw-r--r--test/support/queue_classic/inline.rb11
7 files changed, 42 insertions, 4 deletions
diff --git a/Gemfile b/Gemfile
index 9f74b017f0..550da15615 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,3 +7,4 @@ gem 'resque'
gem 'sidekiq'
gem 'sucker_punch'
gem 'delayed_job'
+gem 'queue_classic'
diff --git a/Gemfile.lock b/Gemfile.lock
index 849ccf6634..c1df0ebc36 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -31,6 +31,9 @@ GEM
minitest (5.3.4)
mono_logger (1.1.0)
multi_json (1.9.3)
+ pg (0.17.1)
+ queue_classic (2.2.3)
+ pg (~> 0.17.0)
rack (1.5.2)
rack-protection (1.5.2)
rack
@@ -70,6 +73,7 @@ PLATFORMS
DEPENDENCIES
activejob!
delayed_job
+ queue_classic
rake
resque
sidekiq
diff --git a/README.md b/README.md
index da73276e84..a0e5f01e29 100644
--- a/README.md
+++ b/README.md
@@ -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.
@@ -83,10 +83,10 @@ We currently have adapters for:
* Sidekiq
* Sucker Punch
* Delayed Job
+* QueueClassic
We would like to have adapters for:
-* QueueClassic
* Sneakers
diff --git a/Rakefile b/Rakefile
index 5242926c7f..2b8b81248d 100644
--- a/Rakefile
+++ b/Rakefile
@@ -20,11 +20,11 @@ task :default => :test
desc 'Run all adapter tests'
task :test do
- tasks = %w(test_inline test_resque test_sidekiq test_sucker_punch test_delayed_job)
+ tasks = %w(test_inline test_resque test_sidekiq test_sucker_punch test_delayed_job test_queue_classic)
run_without_aborting(*tasks)
end
-%w(inline resque sidekiq sucker_punch delayed_job).each do |adapter|
+%w(inline resque sidekiq sucker_punch delayed_job queue_classic).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/queue_adapters/queue_classic_adapter.rb b/lib/active_job/queue_adapters/queue_classic_adapter.rb
new file mode 100644
index 0000000000..e3392a646e
--- /dev/null
+++ b/lib/active_job/queue_adapters/queue_classic_adapter.rb
@@ -0,0 +1,20 @@
+require 'queue_classic'
+
+module ActiveJob
+ module QueueAdapters
+ class QueueClassicAdapter
+ class << self
+ def queue(job, *args)
+ qc_queue = QC::Queue.new(job.queue_name)
+ qc_queue.enqueue("ActiveJob::QueueAdapters::QueueClassicAdapter::JobWrapper.perform", job, *args)
+ end
+ end
+
+ class JobWrapper
+ def self.perform(job, *args)
+ job.new.perform *Parameters.deserialize(args)
+ end
+ end
+ end
+ end
+end
diff --git a/test/adapters/queue_classic.rb b/test/adapters/queue_classic.rb
new file mode 100644
index 0000000000..ad5ced3cc2
--- /dev/null
+++ b/test/adapters/queue_classic.rb
@@ -0,0 +1,2 @@
+require 'support/queue_classic/inline'
+ActiveJob::Base.queue_adapter = :queue_classic
diff --git a/test/support/queue_classic/inline.rb b/test/support/queue_classic/inline.rb
new file mode 100644
index 0000000000..5e9c295e01
--- /dev/null
+++ b/test/support/queue_classic/inline.rb
@@ -0,0 +1,11 @@
+require 'queue_classic'
+
+module QC
+ class Queue
+ def enqueue(method, *args)
+ receiver_str, _, message = method.rpartition('.')
+ receiver = eval(receiver_str)
+ receiver.send(message, *args)
+ end
+ end
+end