push updates to backups list to client

This commit is contained in:
Régis Hanol 2018-01-31 12:05:06 +01:00
parent 38b6c1d67f
commit d233ecbe34
4 changed files with 32 additions and 27 deletions

View File

@ -1,7 +1,15 @@
import Backup from 'admin/models/backup';
export default Ember.Route.extend({
activate() {
this.messageBus.subscribe("/admin/backups", backups => this.controller.set("model", backups));
},
model() {
return Backup.find();
},
deactivate() {
this.messageBus.unsubscribe("/admin/backups");
}
});

View File

@ -9,26 +9,24 @@ const LOG_CHANNEL = "/admin/backups/logs";
export default Discourse.Route.extend({
activate() {
this.messageBus.subscribe(LOG_CHANNEL, this._processLogMessage.bind(this));
},
_processLogMessage(log) {
if (log.message === "[STARTED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", true);
this.controllerFor("adminBackupsLogs").get('logs').clear();
} else if (log.message === "[FAILED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
bootbox.alert(I18n.t("admin.backups.operations.failed", { operation: log.operation }));
} else if (log.message === "[SUCCESS]") {
Discourse.User.currentProp("hideReadOnlyAlert", false);
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
if (log.operation === "restore") {
// redirect to homepage when the restore is done (session might be lost)
window.location.pathname = Discourse.getURL("/");
this.messageBus.subscribe(LOG_CHANNEL, (log) => {
if (log.message === "[STARTED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", true);
this.controllerFor("adminBackupsLogs").get('logs').clear();
} else if (log.message === "[FAILED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
bootbox.alert(I18n.t("admin.backups.operations.failed", { operation: log.operation }));
} else if (log.message === "[SUCCESS]") {
Discourse.User.currentProp("hideReadOnlyAlert", false);
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
if (log.operation === "restore") {
// redirect to homepage when the restore is done (session might be lost)
window.location.pathname = Discourse.getURL("/");
}
} else {
this.controllerFor("adminBackupsLogs").get('logs').pushObject(Em.Object.create(log));
}
} else {
this.controllerFor("adminBackupsLogs").get('logs').pushObject(Em.Object.create(log));
}
});
},
model() {
@ -122,12 +120,7 @@ export default Discourse.Route.extend({
},
uploadSuccess(filename) {
const self = this;
bootbox.alert(I18n.t("admin.backups.upload.success", { filename: filename }), function() {
Backup.find().then(function (backups) {
self.controllerFor("adminBackupsIndex").set("model", backups);
});
});
bootbox.alert(I18n.t("admin.backups.upload.success", { filename: filename }));
},
uploadError(filename, message) {

View File

@ -1,7 +1,7 @@
module Jobs
class BackupChunksMerger < Jobs::Base
sidekiq_options retry: false
sidekiq_options queue: 'critical', retry: false
def execute(args)
filename = args[:filename]
@ -19,6 +19,10 @@ module Jobs
# merge all chunks
HandleChunkUpload.merge_chunks(chunks, upload_path: backup_path, tmp_upload_path: tmp_backup_path, model: Backup, identifier: identifier, filename: filename, tmp_directory: tmp_directory)
# push an updated list to the clients
data = ActiveModel::ArraySerializer.new(Backup.all, each_serializer: BackupSerializer).as_json
MessageBus.publish("/admin/backups", data, user_ids: User.staff.pluck(:id))
end
end

View File

@ -2894,7 +2894,7 @@ en:
label: "Upload"
title: "Upload a backup to this instance"
uploading: "Uploading..."
success: "'{{filename}}' has successfully been uploaded."
success: "'{{filename}}' has successfully been uploaded. The file is now being processed and will take up to a minute to show up in the list."
error: "There has been an error while uploading '{{filename}}': {{message}}"
operations:
is_running: "An operation is currently running..."