mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Initial queue implementation
This commit is contained in:
parent
770c809db4
commit
adff4a706a
8 changed files with 45 additions and 3 deletions
|
@ -22,6 +22,7 @@ end
|
|||
module Rails
|
||||
autoload :Info, 'rails/info'
|
||||
autoload :InfoController, 'rails/info_controller'
|
||||
autoload :Queueing, 'rails/queueing'
|
||||
|
||||
class << self
|
||||
def application
|
||||
|
@ -37,6 +38,25 @@ module Rails
|
|||
application.config
|
||||
end
|
||||
|
||||
# Rails.queue is the application's queue. You can push a job onto
|
||||
# the queue by:
|
||||
#
|
||||
# Rails.queue.push job
|
||||
#
|
||||
# A job is an object that responds to +run+. Queue consumers will
|
||||
# pop jobs off of the queue and invoke the queue's +run+ method.
|
||||
#
|
||||
# Note that depending on your queue implementation, jobs may not
|
||||
# be executed in the same process as they were created in, and
|
||||
# are never executed in the same thread as they were created in.
|
||||
#
|
||||
# If necessary, a queue implementation may need to serialize your
|
||||
# job for distribution to another process. The documentation of
|
||||
# your queue will specify the requirements for that serialization.
|
||||
def queue
|
||||
application.queue
|
||||
end
|
||||
|
||||
def initialize!
|
||||
application.initialize!
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@ module Rails
|
|||
end
|
||||
end
|
||||
|
||||
attr_accessor :assets, :sandbox
|
||||
attr_accessor :assets, :sandbox, :queue
|
||||
alias_method :sandbox?, :sandbox
|
||||
attr_reader :reloaders
|
||||
|
||||
|
@ -199,6 +199,10 @@ module Rails
|
|||
@config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd))
|
||||
end
|
||||
|
||||
def queue #:nodoc:
|
||||
@queue ||= config.queue.new
|
||||
end
|
||||
|
||||
def to_app
|
||||
self
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module Rails
|
|||
:force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags, :preload_frameworks,
|
||||
:railties_order, :relative_url_root, :secret_token,
|
||||
:serve_static_assets, :ssl_options, :static_cache_control, :session_options,
|
||||
:time_zone, :reload_classes_only_on_change, :use_schema_cache_dump
|
||||
:time_zone, :reload_classes_only_on_change, :use_schema_cache_dump, :queue
|
||||
|
||||
attr_writer :log_level
|
||||
attr_reader :encoding
|
||||
|
@ -43,6 +43,7 @@ module Rails
|
|||
@autoflush_log = true
|
||||
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
|
||||
@use_schema_cache_dump = true
|
||||
@queue = Queue
|
||||
|
||||
@assets = ActiveSupport::OrderedOptions.new
|
||||
@assets.enabled = false
|
||||
|
|
|
@ -93,6 +93,13 @@ module Rails
|
|||
ActiveSupport::Dependencies.unhook!
|
||||
end
|
||||
end
|
||||
|
||||
initializer :activate_queue_consumer do |app|
|
||||
if config.queue == Queue
|
||||
consumer = Rails::Queueing::ThreadedConsumer.start(app.queue)
|
||||
at_exit { consumer.shutdown }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,4 +35,7 @@
|
|||
# Expands the lines which load the assets.
|
||||
config.assets.debug = true
|
||||
<%- end -%>
|
||||
|
||||
# In development, use an in-memory queue for queueing
|
||||
config.queue = Queue
|
||||
end
|
||||
|
|
|
@ -76,4 +76,8 @@
|
|||
|
||||
# Use default logging formatter so that PID and timestamp are not suppressed
|
||||
config.log_formatter = ::Logger::Formatter.new
|
||||
|
||||
# Default the production mode queue to an in-memory queue. You will probably
|
||||
# want to replace this with an out-of-process queueing solution
|
||||
config.queue = Queue
|
||||
end
|
||||
|
|
|
@ -33,4 +33,7 @@
|
|||
|
||||
# Print deprecation notices to the stderr.
|
||||
config.active_support.deprecation = :stderr
|
||||
|
||||
# Use the testing queue
|
||||
config.queue = Rails::Queueing::TestQueue
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# Rails booted up.
|
||||
require 'fileutils'
|
||||
|
||||
require 'rubygems'
|
||||
require 'bundler/setup'
|
||||
require 'minitest/autorun'
|
||||
require 'active_support/test_case'
|
||||
|
||||
|
|
Loading…
Reference in a new issue