mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: send the backup/restore logs when operation fails
This commit is contained in:
parent
9454ad1ef9
commit
0def4747da
3 changed files with 60 additions and 20 deletions
|
@ -1154,10 +1154,32 @@ en:
|
|||
subject_template: "Export completed successfully"
|
||||
text_body_template: "The export was successful."
|
||||
|
||||
export_failed:
|
||||
subject_template: "Export failed"
|
||||
text_body_template: |
|
||||
The export has failed.
|
||||
|
||||
Here's the log:
|
||||
|
||||
```
|
||||
%{logs}
|
||||
```
|
||||
|
||||
import_succeeded:
|
||||
subject_template: "Import completed successfully"
|
||||
text_body_template: "The import was successful."
|
||||
|
||||
import_failed:
|
||||
subject_template: "Import failed"
|
||||
text_body_template: |
|
||||
The import has failed.
|
||||
|
||||
Here's the log:
|
||||
|
||||
```
|
||||
%{logs}
|
||||
```
|
||||
|
||||
email_error_notification:
|
||||
subject_template: "Error parsing email"
|
||||
text_body_template: |
|
||||
|
|
|
@ -44,8 +44,6 @@ module Export
|
|||
after_create_hook
|
||||
|
||||
remove_old
|
||||
|
||||
notify_user
|
||||
rescue SystemExit
|
||||
log "Backup process was cancelled!"
|
||||
rescue Exception => ex
|
||||
|
@ -55,6 +53,7 @@ module Export
|
|||
@success = true
|
||||
"#{@archive_basename}.tar.gz"
|
||||
ensure
|
||||
notify_user
|
||||
clean_up
|
||||
@success ? log("[SUCCESS]") : log("[FAILED]")
|
||||
end
|
||||
|
@ -79,6 +78,7 @@ module Export
|
|||
@meta_filename = File.join(@tmp_directory, BackupRestore::METADATA_FILE)
|
||||
@archive_directory = File.join(Rails.root, "public", "backups", @current_db)
|
||||
@archive_basename = File.join(@archive_directory, "#{SiteSetting.title.parameterize}-#{@timestamp}")
|
||||
@logs = []
|
||||
end
|
||||
|
||||
def listen_for_shutdown_signal
|
||||
|
@ -256,17 +256,21 @@ module Export
|
|||
backup.after_create_hook
|
||||
end
|
||||
|
||||
def notify_user
|
||||
log "Notifying '#{@user.username}' of the success of the backup..."
|
||||
# NOTE: will only notify if @user != Discourse.site_contact_user
|
||||
SystemMessage.create(@user, :export_succeeded)
|
||||
end
|
||||
|
||||
def remove_old
|
||||
log "Removing old backups..."
|
||||
Backup.remove_old
|
||||
end
|
||||
|
||||
def notify_user
|
||||
log "Notifying '#{@user.username}' of the end of the backup..."
|
||||
# NOTE: will only notify if @user != Discourse.site_contact_user
|
||||
if @success
|
||||
SystemMessage.create(@user, :export_succeeded)
|
||||
else
|
||||
SystemMessage.create(@user, :export_failed, logs: @logs.join("\n"))
|
||||
end
|
||||
end
|
||||
|
||||
def clean_up
|
||||
log "Cleaning stuff up..."
|
||||
remove_tmp_directory
|
||||
|
@ -306,6 +310,7 @@ module Export
|
|||
def log(message)
|
||||
puts(message) rescue nil
|
||||
publish_log(message) rescue nil
|
||||
save_log(message)
|
||||
end
|
||||
|
||||
def publish_log(message)
|
||||
|
@ -314,6 +319,10 @@ module Export
|
|||
MessageBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id])
|
||||
end
|
||||
|
||||
def save_log(message)
|
||||
@logs << "[#{Time.now}] #{message}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -48,8 +48,6 @@ module Import
|
|||
reconnect_database
|
||||
|
||||
extract_uploads
|
||||
|
||||
notify_user
|
||||
rescue SystemExit
|
||||
log "Restore process was cancelled!"
|
||||
rollback
|
||||
|
@ -60,6 +58,7 @@ module Import
|
|||
else
|
||||
@success = true
|
||||
ensure
|
||||
notify_user
|
||||
clean_up
|
||||
@success ? log("[SUCCESS]") : log("[FAILED]")
|
||||
end
|
||||
|
@ -95,6 +94,7 @@ module Import
|
|||
@tar_filename = @archive_filename[0...-3]
|
||||
@meta_filename = File.join(@tmp_directory, BackupRestore::METADATA_FILE)
|
||||
@dump_filename = File.join(@tmp_directory, BackupRestore::DUMP_FILE)
|
||||
@logs << []
|
||||
end
|
||||
|
||||
def listen_for_shutdown_signal
|
||||
|
@ -256,16 +256,6 @@ module Import
|
|||
end
|
||||
end
|
||||
|
||||
def notify_user
|
||||
if user = User.where(email: @user_info[:email]).first
|
||||
log "Notifying '#{user.username}' of the success of the restore..."
|
||||
# NOTE: will only notify if user != Discourse.site_contact_user
|
||||
SystemMessage.create(user, :import_succeeded)
|
||||
else
|
||||
log "Could not send notification to '#{@user_info[:username]}' (#{@user_info[:email]}), because the user does not exists..."
|
||||
end
|
||||
end
|
||||
|
||||
def rollback
|
||||
log "Trying to rollback..."
|
||||
if BackupRestore.can_rollback?
|
||||
|
@ -276,6 +266,20 @@ module Import
|
|||
end
|
||||
end
|
||||
|
||||
def notify_user
|
||||
if user = User.where(email: @user_info[:email]).first
|
||||
log "Notifying '#{user.username}' of the end of the restore..."
|
||||
# NOTE: will only notify if user != Discourse.site_contact_user
|
||||
if @success
|
||||
SystemMessage.create(user, :import_succeeded)
|
||||
else
|
||||
SystemMessage.create(user, :import_failed, logs: @logs.join("\n"))
|
||||
end
|
||||
else
|
||||
log "Could not send notification to '#{@user_info[:username]}' (#{@user_info[:email]}), because the user does not exists..."
|
||||
end
|
||||
end
|
||||
|
||||
def clean_up
|
||||
log "Cleaning stuff up..."
|
||||
remove_tmp_directory
|
||||
|
@ -315,6 +319,7 @@ module Import
|
|||
def log(message)
|
||||
puts(message) rescue nil
|
||||
publish_log(message) rescue nil
|
||||
save_log(message)
|
||||
end
|
||||
|
||||
def publish_log(message)
|
||||
|
@ -323,6 +328,10 @@ module Import
|
|||
MessageBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id])
|
||||
end
|
||||
|
||||
def save_log(message)
|
||||
@logs << "[#{Time.now}] #{message}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue