mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:16:41 +08:00
BUGFIX: scheduler was showing up empty in multisite
This commit is contained in:
parent
5b559d9631
commit
f27ffe3223
|
@ -1,26 +1,30 @@
|
|||
# Based off sidetiq https://github.com/tobiassvn/sidetiq/blob/master/lib/sidetiq/web.rb
|
||||
module Scheduler
|
||||
module Web
|
||||
VIEWS = File.expand_path('views', File.dirname(__FILE__))
|
||||
VIEWS = File.expand_path('views', File.dirname(__FILE__)) unless defined? VIEWS
|
||||
|
||||
def self.registered(app)
|
||||
app.get "/scheduler" do
|
||||
@manager = Scheduler::Manager.without_runner
|
||||
@schedules = Scheduler::Manager.discover_schedules.sort do |a,b|
|
||||
a.schedule_info.next_run <=> b.schedule_info.next_run
|
||||
RailsMultisite::ConnectionManagement.with_connection("default") do
|
||||
@manager = Scheduler::Manager.without_runner
|
||||
@schedules = Scheduler::Manager.discover_schedules.sort do |a,b|
|
||||
a.schedule_info.next_run <=> b.schedule_info.next_run
|
||||
end
|
||||
erb File.read(File.join(VIEWS, 'scheduler.erb')), locals: {view_path: VIEWS}
|
||||
end
|
||||
erb File.read(File.join(VIEWS, 'scheduler.erb')), locals: {view_path: VIEWS}
|
||||
end
|
||||
|
||||
app.post "/scheduler/:name/trigger" do
|
||||
halt 404 unless (name = params[:name])
|
||||
|
||||
klass = name.constantize
|
||||
info = klass.schedule_info
|
||||
info.next_run = Time.now.to_f
|
||||
info.write!
|
||||
RailsMultisite::ConnectionManagement.with_connection("default") do
|
||||
klass = name.constantize
|
||||
info = klass.schedule_info
|
||||
info.next_run = Time.now.to_f
|
||||
info.write!
|
||||
|
||||
redirect "#{root_path}scheduler"
|
||||
redirect "#{root_path}scheduler"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -37,6 +37,20 @@ module RailsMultisite
|
|||
end
|
||||
end
|
||||
|
||||
def self.with_connection(db = "default")
|
||||
old = current_db
|
||||
connected = ActiveRecord::Base.connection_pool.connected?
|
||||
|
||||
establish_connection(:db => db)
|
||||
rval = yield db
|
||||
ActiveRecord::Base.connection_handler.clear_active_connections!
|
||||
|
||||
establish_connection(:db => old)
|
||||
ActiveRecord::Base.connection_handler.clear_active_connections! unless connected
|
||||
|
||||
rval
|
||||
end
|
||||
|
||||
def self.each_connection
|
||||
old = current_db
|
||||
connected = ActiveRecord::Base.connection_pool.connected?
|
||||
|
@ -59,7 +73,7 @@ module RailsMultisite
|
|||
end
|
||||
|
||||
def self.current_db
|
||||
db = ActiveRecord::Base.connection_pool.spec.config[:db_key] || "default"
|
||||
ActiveRecord::Base.connection_pool.spec.config[:db_key] || "default"
|
||||
end
|
||||
|
||||
def self.config_filename=(config_filename)
|
||||
|
|
Loading…
Reference in New Issue
Block a user