Use the SynchronousQueue as default in production and development.

We should not let the users use the ThreadedConsumer without know about
the risks
上级 079eed83
...@@ -42,6 +42,6 @@ ...@@ -42,6 +42,6 @@
config.assets.debug = true config.assets.debug = true
<%- end -%> <%- end -%>
# In development, use an in-memory queue for queueing. # In development, use an synchronous queue for queueing.
config.queue = Rails::Queueing::Queue config.queue = Rails::Queueing::SynchronousQueue
end end
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
# Use default logging formatter so that PID and timestamp are not suppressed. # Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new config.log_formatter = ::Logger::Formatter.new
# Default the production mode queue to an in-memory queue. You will probably # Default the production mode queue to an synchronous queue. You will probably
# want to replace this with an out-of-process queueing solution. # want to replace this with an out-of-process queueing solution.
config.queue = Rails::Queueing::Queue config.queue = Rails::Queueing::SynchronousQueue
end end
...@@ -23,10 +23,10 @@ def app_const ...@@ -23,10 +23,10 @@ def app_const
assert_kind_of Rails::Queueing::TestQueue, Rails.queue[:default] assert_kind_of Rails::Queueing::TestQueue, Rails.queue[:default]
end end
test "the queue is a Queue in development mode" do test "the queue is a SynchronousQueue in development mode" do
app("development") app("development")
assert_kind_of Rails::Queueing::Queue, Rails.application.queue[:default] assert_kind_of Rails::Queueing::SynchronousQueue, Rails.application.queue[:default]
assert_kind_of Rails::Queueing::Queue, Rails.queue[:default] assert_kind_of Rails::Queueing::SynchronousQueue, Rails.queue[:default]
end end
class ThreadTrackingJob class ThreadTrackingJob
...@@ -47,7 +47,7 @@ def ran? ...@@ -47,7 +47,7 @@ def ran?
end end
end end
test "in development mode, an enqueued job will be processed in a separate thread" do test "in development mode, an enqueued job will be processed in the same thread" do
app("development") app("development")
job = ThreadTrackingJob.new job = ThreadTrackingJob.new
...@@ -55,7 +55,7 @@ def ran? ...@@ -55,7 +55,7 @@ def ran?
sleep 0.1 sleep 0.1
assert job.ran?, "Expected job to be run" assert job.ran?, "Expected job to be run"
assert job.ran_in_different_thread?, "Expected job to run in a different thread" refute job.ran_in_different_thread?, "Expected job to run in the same thread"
end end
test "in test mode, explicitly draining the queue will process it in a separate thread" do test "in test mode, explicitly draining the queue will process it in a separate thread" do
...@@ -160,6 +160,7 @@ def run ...@@ -160,6 +160,7 @@ def run
test "a custom consumer implementation can be provided" do test "a custom consumer implementation can be provided" do
add_to_env_config "production", <<-RUBY add_to_env_config "production", <<-RUBY
require "my_queue_consumer" require "my_queue_consumer"
config.queue = Rails::Queueing::Queue
config.queue_consumer = MyQueueConsumer config.queue_consumer = MyQueueConsumer
RUBY RUBY
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册