mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add Sidekiq adapter/wrapper fixes #3
This commit is contained in:
parent
ce124a19e5
commit
a712c07c7f
6 changed files with 31 additions and 3 deletions
2
Gemfile
2
Gemfile
|
@ -3,4 +3,4 @@ source 'https://rubygems.org'
|
|||
gemspec
|
||||
|
||||
gem 'resque'
|
||||
|
||||
gem 'sidekiq'
|
||||
|
|
4
Rakefile
4
Rakefile
|
@ -22,12 +22,12 @@ task :default => :test
|
|||
|
||||
desc 'Run all adapter tests'
|
||||
task :test do
|
||||
tasks = %w(test_inline test_resque)
|
||||
tasks = %w(test_inline test_resque test_sidekiq)
|
||||
run_without_aborting(*tasks)
|
||||
end
|
||||
|
||||
|
||||
%w( inline resque ).each do |adapter|
|
||||
%w( inline resque sidekiq ).each do |adapter|
|
||||
Rake::TestTask.new("test_#{adapter}") do |t|
|
||||
t.libs << 'test'
|
||||
t.test_files = FileList['test/cases/**/*_test.rb']
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'active_job/queue_adapters/inline_adapter'
|
||||
require 'active_job/queue_adapters/resque_adapter'
|
||||
require 'active_job/queue_adapters/sidekiq_adapter'
|
||||
|
||||
module ActiveJob
|
||||
class Base
|
||||
|
|
11
lib/active_job/job_wrappers/sidekiq_wrapper.rb
Normal file
11
lib/active_job/job_wrappers/sidekiq_wrapper.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module ActiveJob
|
||||
module JobWrappers
|
||||
class SidekiqWrapper
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(job_name, *args)
|
||||
job_name.constantize.perform(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/active_job/queue_adapters/sidekiq_adapter.rb
Normal file
14
lib/active_job/queue_adapters/sidekiq_adapter.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'sidekiq'
|
||||
require 'active_job/job_wrappers/sidekiq_wrapper'
|
||||
|
||||
module ActiveJob
|
||||
module QueueAdapters
|
||||
class SidekiqAdapter
|
||||
class << self
|
||||
def queue(job, *args)
|
||||
JobWrappers::SidekiqWrapper.perform_async(job, *args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
2
test/adapters/sidekiq.rb
Normal file
2
test/adapters/sidekiq.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
require 'sidekiq/testing/inline'
|
||||
ActiveJob::Base.queue_adapter = ActiveJob::QueueAdapters::SidekiqAdapter
|
Loading…
Reference in a new issue