mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 08:09:33 +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
|
# Based off sidetiq https://github.com/tobiassvn/sidetiq/blob/master/lib/sidetiq/web.rb
|
||||||
module Scheduler
|
module Scheduler
|
||||||
module Web
|
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)
|
def self.registered(app)
|
||||||
app.get "/scheduler" do
|
app.get "/scheduler" do
|
||||||
@manager = Scheduler::Manager.without_runner
|
RailsMultisite::ConnectionManagement.with_connection("default") do
|
||||||
@schedules = Scheduler::Manager.discover_schedules.sort do |a,b|
|
@manager = Scheduler::Manager.without_runner
|
||||||
a.schedule_info.next_run <=> b.schedule_info.next_run
|
@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
|
end
|
||||||
erb File.read(File.join(VIEWS, 'scheduler.erb')), locals: {view_path: VIEWS}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
app.post "/scheduler/:name/trigger" do
|
app.post "/scheduler/:name/trigger" do
|
||||||
halt 404 unless (name = params[:name])
|
halt 404 unless (name = params[:name])
|
||||||
|
|
||||||
klass = name.constantize
|
RailsMultisite::ConnectionManagement.with_connection("default") do
|
||||||
info = klass.schedule_info
|
klass = name.constantize
|
||||||
info.next_run = Time.now.to_f
|
info = klass.schedule_info
|
||||||
info.write!
|
info.next_run = Time.now.to_f
|
||||||
|
info.write!
|
||||||
|
|
||||||
redirect "#{root_path}scheduler"
|
redirect "#{root_path}scheduler"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,6 +37,20 @@ module RailsMultisite
|
||||||
end
|
end
|
||||||
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
|
def self.each_connection
|
||||||
old = current_db
|
old = current_db
|
||||||
connected = ActiveRecord::Base.connection_pool.connected?
|
connected = ActiveRecord::Base.connection_pool.connected?
|
||||||
|
@ -59,7 +73,7 @@ module RailsMultisite
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.current_db
|
def self.current_db
|
||||||
db = ActiveRecord::Base.connection_pool.spec.config[:db_key] || "default"
|
ActiveRecord::Base.connection_pool.spec.config[:db_key] || "default"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.config_filename=(config_filename)
|
def self.config_filename=(config_filename)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user