forked from rails/rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
153 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ gem 'sidekiq' | |
gem 'sucker_punch' | ||
gem 'delayed_job' | ||
gem 'queue_classic' | ||
gem 'sneakers', '0.1.1.pre' | ||
gem 'que' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
require 'active_job/queue_adapter' | ||
require 'active_job/queue_name' | ||
require 'active_job/enqueuing' | ||
require 'active_job/logging' | ||
|
||
module ActiveJob | ||
class Base | ||
extend QueueAdapter | ||
extend QueueName | ||
extend Enqueuing | ||
extend Logging | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module ActiveJob | ||
class LogSubscriber < ActiveSupport::LogSubscriber | ||
def enqueue(event) | ||
payload = event.payload | ||
params = payload[:params] | ||
adapter = payload[:adapter] | ||
job = payload[:job] | ||
|
||
info "ActiveJob enqueued to #{adapter.name.demodulize} job #{job.name}: #{params.inspect}" | ||
end | ||
|
||
def logger | ||
ActiveJob::Base.logger | ||
end | ||
end | ||
end | ||
|
||
ActiveJob::LogSubscriber.attach_to :active_job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'active_job/log_subscriber' | ||
|
||
module ActiveJob | ||
module Logging | ||
mattr_accessor(:logger) { ActiveSupport::Logger.new(STDOUT) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'que' | ||
|
||
module ActiveJob | ||
module QueueAdapters | ||
class QueAdapter | ||
class << self | ||
def queue(job, *args) | ||
JobWrapper.enqueue job, *args, queue: job.queue_name | ||
end | ||
end | ||
|
||
class JobWrapper < Que::Job | ||
def run(job, *args) | ||
job.new.perform *Parameters.deserialize(args) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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(job, *args) | ||
job.new.perform *Parameters.deserialize(args) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ActiveJob::Base.queue_adapter = :que | ||
Que.mode = :sync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'support/sneakers/inline' | ||
ActiveJob::Base.queue_adapter = :sneakers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
require 'helper' | ||
|
||
class AdapterTest < ActiveSupport::TestCase | ||
def setup | ||
@old_adapter = ActiveJob::Base.queue_adapter | ||
end | ||
setup { @old_adapter = ActiveJob::Base.queue_adapter } | ||
teardown { ActiveJob::Base.queue_adapter = @old_adapter } | ||
|
||
test 'should load inline adapter' do | ||
ActiveJob::Base.queue_adapter = :inline | ||
assert_equal ActiveJob::QueueAdapters::InlineAdapter, ActiveJob::Base.queue_adapter | ||
end | ||
|
||
test 'should load resque adapter' do | ||
test 'should load Delayed Job adapter' do | ||
ActiveJob::Base.queue_adapter = :delayed_job | ||
assert_equal ActiveJob::QueueAdapters::DelayedJobAdapter, 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 | ||
end | ||
|
||
test 'should load Queue Classic adapter' do | ||
ActiveJob::Base.queue_adapter = :queue_classic | ||
assert_equal ActiveJob::QueueAdapters::QueueClassicAdapter, ActiveJob::Base.queue_adapter | ||
end | ||
|
||
test 'should load Resque adapter' do | ||
ActiveJob::Base.queue_adapter = :resque | ||
assert_equal ActiveJob::QueueAdapters::ResqueAdapter, ActiveJob::Base.queue_adapter | ||
end | ||
|
||
test 'should load sidekiq adapter' do | ||
test 'should load Sidekiq adapter' do | ||
ActiveJob::Base.queue_adapter = :sidekiq | ||
assert_equal ActiveJob::QueueAdapters::SidekiqAdapter, ActiveJob::Base.queue_adapter | ||
end | ||
|
||
test 'should load sucker punch adapter' do | ||
test 'should load Sucker Punch adapter' do | ||
ActiveJob::Base.queue_adapter = :sucker_punch | ||
assert_equal ActiveJob::QueueAdapters::SuckerPunchAdapter, ActiveJob::Base.queue_adapter | ||
end | ||
|
||
test 'should load delayed_job adapter' do | ||
ActiveJob::Base.queue_adapter = :delayed_job | ||
assert_equal ActiveJob::QueueAdapters::DelayedJobAdapter, ActiveJob::Base.queue_adapter | ||
end | ||
|
||
def teardown | ||
ActiveJob::Base.queue_adapter = @old_adapter | ||
test 'should load Sneakers adapter' do | ||
ActiveJob::Base.queue_adapter = :sneakers | ||
assert_equal ActiveJob::QueueAdapters::SneakersAdapter, ActiveJob::Base.queue_adapter | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |