From 1b71fe59b8cd6c7347729703c064b64866b3502e Mon Sep 17 00:00:00 2001 From: John DeSilva Date: Tue, 20 May 2014 00:56:08 +0200 Subject: [PATCH] Add Sneakers wrapper --- Gemfile | 1 + Gemfile.lock | 14 +++++++++++ README.md | 3 --- Rakefile | 4 ++-- .../queue_adapters/sneakers_adapter.rb | 24 +++++++++++++++++++ test/adapters/sneakers.rb | 2 ++ test/support/sneakers/inline.rb | 12 ++++++++++ 7 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 lib/active_job/queue_adapters/sneakers_adapter.rb create mode 100644 test/adapters/sneakers.rb create mode 100644 test/support/sneakers/inline.rb diff --git a/Gemfile b/Gemfile index 550da15615..e40962dc92 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,4 @@ gem 'sidekiq' gem 'sucker_punch' gem 'delayed_job' gem 'queue_classic' +gem 'sneakers', '0.1.1.pre' diff --git a/Gemfile.lock b/Gemfile.lock index c1df0ebc36..5f5745b53b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,7 +20,10 @@ GEM minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) + amq-protocol (1.9.2) builder (3.2.2) + bunny (1.1.9) + amq-protocol (>= 1.9.2) celluloid (0.15.2) timers (~> 1.1.0) connection_pool (2.0.0) @@ -47,18 +50,28 @@ GEM redis-namespace (~> 1.2) sinatra (>= 0.9.2) vegas (~> 0.1.2) + serverengine (1.5.7) + sigdump (~> 0.2.2) sidekiq (3.0.2) celluloid (>= 0.15.2) connection_pool (>= 2.0.0) json redis (>= 3.0.6) redis-namespace (>= 1.3.1) + sigdump (0.2.2) sinatra (1.4.4) rack (~> 1.4) rack-protection (~> 1.4) tilt (~> 1.3, >= 1.3.4) + sneakers (0.1.1.pre) + bunny (~> 1.1.3) + serverengine + thor + thread sucker_punch (1.0.5) celluloid (~> 0.15.2) + thor (0.19.1) + thread (0.1.4) thread_safe (0.3.3) tilt (1.4.1) timers (1.1.0) @@ -77,4 +90,5 @@ DEPENDENCIES rake resque sidekiq + sneakers (= 0.1.1.pre) sucker_punch diff --git a/README.md b/README.md index a0e5f01e29..588f0a2a2e 100644 --- a/README.md +++ b/README.md @@ -84,9 +84,6 @@ We currently have adapters for: * Sucker Punch * Delayed Job * QueueClassic - -We would like to have adapters for: - * Sneakers diff --git a/Rakefile b/Rakefile index 2b8b81248d..e0d8e8e0d8 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 test_queue_classic) + tasks = %w(test_inline test_resque test_sidekiq test_sucker_punch test_delayed_job test_queue_classic test_sneakers) run_without_aborting(*tasks) end -%w(inline resque sidekiq sucker_punch delayed_job queue_classic).each do |adapter| +%w(inline resque sidekiq sucker_punch delayed_job queue_classic sneakers).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/sneakers_adapter.rb b/lib/active_job/queue_adapters/sneakers_adapter.rb new file mode 100644 index 0000000000..be400dc477 --- /dev/null +++ b/lib/active_job/queue_adapters/sneakers_adapter.rb @@ -0,0 +1,24 @@ +require 'sneakers' + +module ActiveJob + module QueueAdapters + class SneakersAdapter + class << self + def queue(job, *args) + JobWrapper.enqueue([job, *args]) + end + end + + class JobWrapper + include Sneakers::Worker + + self.from_queue("queue", {}) + + def work(*args) + job_name = args.shift + job_name.new.perform *Parameters.deserialize(args) + end + end + end + end +end diff --git a/test/adapters/sneakers.rb b/test/adapters/sneakers.rb new file mode 100644 index 0000000000..204166a700 --- /dev/null +++ b/test/adapters/sneakers.rb @@ -0,0 +1,2 @@ +require 'support/sneakers/inline' +ActiveJob::Base.queue_adapter = :sneakers diff --git a/test/support/sneakers/inline.rb b/test/support/sneakers/inline.rb new file mode 100644 index 0000000000..16d9b830fa --- /dev/null +++ b/test/support/sneakers/inline.rb @@ -0,0 +1,12 @@ +require 'sneakers' + +module Sneakers + module Worker + module ClassMethods + def enqueue(msg) + worker = self.new(nil, nil, {}) + worker.work(*msg) + end + end + end +end