mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 20:27:28 +08:00
display/preload the logs of the last/current operation
This commit is contained in:
parent
50273ba815
commit
b89d328de2
|
@ -2,13 +2,14 @@ require_dependency "backup_restore"
|
|||
|
||||
class Admin::BackupsController < Admin::AdminController
|
||||
|
||||
skip_before_filter :check_xhr, only: [:index, :show]
|
||||
skip_before_filter :check_xhr, only: [:index, :show, :logs]
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
store_preloaded("backups", MultiJson.dump(serialize_data(Backup.all, BackupSerializer)))
|
||||
store_preloaded("operations_status", MultiJson.dump(BackupRestore.operations_status))
|
||||
store_preloaded("logs", MultiJson.dump(BackupRestore.logs))
|
||||
render "default/empty"
|
||||
end
|
||||
format.json do
|
||||
|
@ -55,6 +56,7 @@ class Admin::BackupsController < Admin::AdminController
|
|||
|
||||
def logs
|
||||
store_preloaded("operations_status", MultiJson.dump(BackupRestore.operations_status))
|
||||
store_preloaded("logs", MultiJson.dump(BackupRestore.logs))
|
||||
render "default/empty"
|
||||
end
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ module BackupRestore
|
|||
|
||||
DUMP_FILE = "dump.sql"
|
||||
METADATA_FILE = "meta.json"
|
||||
LOGS_CHANNEL = "/admin/backups/logs"
|
||||
|
||||
def self.backup!(user_id, publish_to_message_bus = false)
|
||||
exporter = Export::Exporter.new(user_id, publish_to_message_bus)
|
||||
|
@ -32,8 +33,10 @@ module BackupRestore
|
|||
end
|
||||
|
||||
def self.mark_as_running!
|
||||
# TODO: should acquire a lock and raise an exception if already running!
|
||||
# TODO: for more safety, it should acquire a lock
|
||||
# and raise an exception if already running!
|
||||
$redis.set(running_key, "1")
|
||||
save_start_logs_message_id
|
||||
end
|
||||
|
||||
def self.is_operation_running?
|
||||
|
@ -59,6 +62,11 @@ module BackupRestore
|
|||
}
|
||||
end
|
||||
|
||||
def self.logs
|
||||
id = start_logs_message_id
|
||||
MessageBus.backlog(LOGS_CHANNEL, id).map { |m| m.data }
|
||||
end
|
||||
|
||||
def self.current_version
|
||||
ActiveRecord::Migrator.current_version
|
||||
end
|
||||
|
@ -96,6 +104,19 @@ module BackupRestore
|
|||
$redis.del(shutdown_signal_key)
|
||||
end
|
||||
|
||||
def self.save_start_logs_message_id
|
||||
id = MessageBus.last_id(LOGS_CHANNEL)
|
||||
$redis.set(start_logs_message_id_key, id)
|
||||
end
|
||||
|
||||
def self.start_logs_message_id
|
||||
$redis.get(start_logs_message_id_key).to_i
|
||||
end
|
||||
|
||||
def self.start_logs_message_id_key
|
||||
"start_logs_message_id"
|
||||
end
|
||||
|
||||
def self.start!(runner)
|
||||
child = fork do
|
||||
begin
|
||||
|
|
|
@ -296,7 +296,7 @@ module Export
|
|||
def publish_log(message)
|
||||
return unless @publish_to_message_bus
|
||||
data = { timestamp: Time.now, operation: "backup", message: message }
|
||||
MessageBus.publish("/admin/backups/logs", data, user_ids: [@user_id])
|
||||
MessageBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -319,7 +319,7 @@ module Import
|
|||
def publish_log(message)
|
||||
return unless @publish_to_message_bus
|
||||
data = { timestamp: Time.now, operation: "restore", message: message }
|
||||
MessageBus.publish("/admin/backups/logs", data, user_ids: [@user_id])
|
||||
MessageBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -16,13 +16,16 @@ describe Admin::BackupsController do
|
|||
|
||||
context "html format" do
|
||||
|
||||
it "preloads both backups and operations_status" do
|
||||
it "preloads important data" do
|
||||
Backup.expects(:all).returns([])
|
||||
subject.expects(:store_preloaded).with("backups", "[]")
|
||||
|
||||
BackupRestore.expects(:operations_status).returns({})
|
||||
subject.expects(:store_preloaded).with("operations_status", "{}")
|
||||
|
||||
BackupRestore.expects(:logs).returns([])
|
||||
subject.expects(:store_preloaded).with("logs", "[]")
|
||||
|
||||
xhr :get, :index, format: :html
|
||||
|
||||
response.should be_success
|
||||
|
@ -134,15 +137,17 @@ describe Admin::BackupsController do
|
|||
|
||||
describe ".logs" do
|
||||
|
||||
it "preloads operations_status" do
|
||||
it "preloads important data" do
|
||||
BackupRestore.expects(:operations_status).returns({})
|
||||
subject.expects(:store_preloaded).with("operations_status", "{}")
|
||||
|
||||
BackupRestore.expects(:logs).returns([])
|
||||
subject.expects(:store_preloaded).with("logs", "[]")
|
||||
|
||||
xhr :get, :logs, format: :html
|
||||
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe ".restore" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user