mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 07:51:36 +08:00
added basic passenger support, no long polling but functions
clean up initializers so they are ordered properly
This commit is contained in:
parent
8a91b96ec7
commit
1c8eef7dbd
|
@ -88,11 +88,9 @@ module Discourse
|
|||
# Our templates shouldn't start with 'discourse/templates'
|
||||
config.handlebars.templates_root = 'discourse/templates'
|
||||
|
||||
require 'discourse_redis'
|
||||
# Use redis for our cache
|
||||
redis_config = YAML::load(File.open("#{Rails.root}/config/redis.yml"))[Rails.env]
|
||||
redis_store = ActiveSupport::Cache::RedisStore.new "redis://#{redis_config['host']}:#{redis_config['port']}/#{redis_config['cache_db']}"
|
||||
redis_store.options[:namespace] = -> { DiscourseRedis.namespace }
|
||||
config.cache_store = redis_store
|
||||
config.cache_store = DiscourseRedis.new_redis_store
|
||||
|
||||
# Test with rack::cache disabled. Nginx does this for us
|
||||
config.action_dispatch.rack_cache = nil
|
||||
|
|
20
config/initializers/01-redis.rb
Normal file
20
config/initializers/01-redis.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require "#{Rails.root}/lib/discourse_redis"
|
||||
|
||||
$redis = DiscourseRedis.new
|
||||
|
||||
if Rails.env.development? && !ENV['DO_NOT_FLUSH_REDIS']
|
||||
puts "Flushing redis (development mode)"
|
||||
$redis.flushall
|
||||
end
|
||||
|
||||
if defined?(PhusionPassenger)
|
||||
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
||||
if forked
|
||||
# We're in smart spawning mode.
|
||||
$redis = DiscourseRedis.new
|
||||
Discourse::Application.config.cache_store.reconnect# = DiscourseRedis.new_redis_store
|
||||
else
|
||||
# We're in conservative spawning mode. We don't need to do anything.
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +1,7 @@
|
|||
require "#{Rails.root}/lib/discourse_redis"
|
||||
|
||||
$redis = DiscourseRedis.new
|
||||
|
||||
if Rails.env.development? && !ENV['DO_NOT_FLUSH_REDIS']
|
||||
puts "Flushing redis (development mode)"
|
||||
$redis.flushall
|
||||
end
|
||||
|
||||
Sidekiq.configure_server do |config|
|
||||
config.redis = { :url => $redis.url, :namespace => 'sidekiq' }
|
||||
end
|
||||
|
||||
Sidekiq.configure_client do |config|
|
||||
config.redis = { :url => $redis.url, :namespace => 'sidekiq' }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,6 +35,13 @@ class DiscourseRedis
|
|||
RailsMultisite::ConnectionManagement.current_db
|
||||
end
|
||||
|
||||
def self.new_redis_store
|
||||
redis_config = YAML::load(File.open("#{Rails.root}/config/redis.yml"))[Rails.env]
|
||||
redis_store = ActiveSupport::Cache::RedisStore.new "redis://#{redis_config['host']}:#{redis_config['port']}/#{redis_config['cache_db']}"
|
||||
redis_store.options[:namespace] = -> { DiscourseRedis.namespace }
|
||||
redis_store
|
||||
end
|
||||
|
||||
def url
|
||||
"redis://#{@config['host']}:#{@config['port']}/#{@config['db']}"
|
||||
end
|
||||
|
|
|
@ -9,8 +9,10 @@ class MessageBus::Rack::Middleware
|
|||
def self.start_listener
|
||||
unless @started_listener
|
||||
MessageBus.subscribe do |msg|
|
||||
EM.next_tick do
|
||||
@@connection_manager.notify_clients(msg) if @@connection_manager
|
||||
if EM.reactor_running?
|
||||
EM.next_tick do
|
||||
@@connection_manager.notify_clients(msg) if @@connection_manager
|
||||
end
|
||||
end
|
||||
end
|
||||
@started_listener = true
|
||||
|
@ -73,7 +75,7 @@ class MessageBus::Rack::Middleware
|
|||
|
||||
if backlog.length > 0
|
||||
[200, headers, [self.class.backlog_to_json(backlog)] ]
|
||||
elsif MessageBus.long_polling_enabled? && env['QUERY_STRING'] !~ /dlp=t/
|
||||
elsif MessageBus.long_polling_enabled? && env['QUERY_STRING'] !~ /dlp=t/ && EM.reactor_running?
|
||||
response = Thin::AsyncResponse.new(env)
|
||||
response.headers["Cache-Control"] = "must-revalidate, private, max-age=0"
|
||||
response.headers["Content-Type"] ="application/json; charset=utf-8"
|
||||
|
|
Loading…
Reference in New Issue
Block a user