1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add ResqueAdapter and provide test infrastructure for the now multiple adapters

This commit is contained in:
David Heinemeier Hansson 2014-05-18 13:11:00 +02:00
parent 30973e35a0
commit eed52c8808
9 changed files with 76 additions and 10 deletions

View file

@ -1,3 +1,6 @@
source 'https://rubygems.org'
gemspec
gemspec
gem 'resque'

View file

@ -16,12 +16,34 @@ GEM
i18n (0.6.9)
json (1.8.1)
minitest (5.3.4)
mono_logger (1.1.0)
multi_json (1.9.3)
rack (1.5.2)
rack-protection (1.5.2)
rack
redis (3.0.7)
redis-namespace (1.4.1)
redis (~> 3.0.4)
resque (1.24.1)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
thread_safe (0.3.3)
tilt (1.4.1)
tzinfo (1.1.0)
thread_safe (~> 0.1)
vegas (0.1.11)
rack (>= 1.0.0)
PLATFORMS
ruby
DEPENDENCIES
activejob!
resque

View file

@ -2,13 +2,44 @@ dir = File.dirname(__FILE__)
require 'rake/testtask'
def run_without_aborting(*tasks)
errors = []
tasks.each do |task|
begin
Rake::Task[task].invoke
rescue Exception
errors << task
end
end
abort "Errors running #{errors.join(', ')}" if errors.any?
end
task :default => :test
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = Dir.glob("#{dir}/test/cases/**/*_test.rb").sort
t.warning = true
t.verbose = true
desc 'Run all adapter tests'
task :test do
tasks = %w(test_inline test_resque)
run_without_aborting(*tasks)
end
%w( inline resque ).each do |adapter|
Rake::TestTask.new("test_#{adapter}") do |t|
t.libs << 'test'
t.test_files = FileList['test/cases/**/*_test.rb']
t.verbose = true
end
namespace adapter do
task :test => "test_#{adapter}"
task(:env) { ENV['AJADAPTER'] = adapter }
end
task "test_#{adapter}" => "#{adapter}:env"
end
require 'rubygems/package_task'

View file

@ -1,10 +1,13 @@
require 'active_job/queue_adapters/inline_queue'
require 'active_job/queue_adapters/inline_adapter'
require 'active_job/queue_adapters/resque_adapter'
module ActiveJob
class Base
cattr_accessor(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter }
class << self
def enqueue(*args)
ActiveJob::QueueAdapters::InlineQueue.queue self, *args
queue_adapter.queue self, *args
end
end
end

View file

@ -1,9 +1,11 @@
require 'resque'
module ActiveJob
module QueueAdapters
class InlineQueue
class ResqueAdapter
class << self
def queue(job, *args)
job.perform *args
Resque.enqueue(job, *args)
end
end
end

0
test/adapters/inline.rb Normal file
View file

2
test/adapters/resque.rb Normal file
View file

@ -0,0 +1,2 @@
ActiveJob::Base.queue_adapter = ActiveJob::QueueAdapters::ResqueAdapter
Resque.inline = true

View file

@ -4,5 +4,6 @@ Bundler.setup
$LOAD_PATH << File.dirname(__FILE__ + "/../lib")
require 'active_job'
require "adapters/#{ENV['AJADAPTER'] || 'inline'}"
require 'active_support/testing/autorun'

View file

@ -1,4 +1,6 @@
class HelloJob < ActiveJob::Base
@queue = :greetings
def self.perform(greeter = "David")
$BUFFER << "#{greeter} says hello"
end