Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

added missing backup job refactoring needed downstream

Markus Kahl8d85b2a1a684
diff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rb
index ed895991957..fafadcea282 100644
--- a/app/workers/backup_job.rb
+++ b/app/workers/backup_job.rb
@@ -53,15 +53,7 @@ class BackupJob < ::ApplicationJob
raise e
ensure
- remove_files! db_dump_file_name, archive_file_name
-
- backup.attachments.each(&:destroy) unless success?
-
- Rails.logger.info(
- "BackupJob(include_attachments: #{include_attachments}) finished " \
- "with status #{job_status.status} " \
- "(dumped: #{dumped?}, archived: #{archived?})"
- )
+ after_backup
end
def run_backup!
@@ -77,6 +69,21 @@ class BackupJob < ::ApplicationJob
store_backup file_name, backup: backup, user: user
cleanup_previous_backups!
+ notify_backup_ready!
+ end
+
+ def after_backup
+ remove_files! db_dump_file_name, archive_file_name
+ remove_backup_attachment! unless success?
+
+ Rails.logger.info(
+ "BackupJob(include_attachments: #{include_attachments?}) finished " \
+ "with status #{status} " \
+ "(dumped: #{dumped?}, archived: #{archived?})"
+ )
+ end
+
+ def notify_backup_ready!
UserMailer.backup_ready(user).deliver_later
end
@@ -88,6 +95,10 @@ class BackupJob < ::ApplicationJob
@archived
end
+ def status
+ job_status.status
+ end
+
def db_dump_file_name
@db_dump_file_name ||= tmp_file_name "openproject", ".sql"
end
@@ -118,6 +129,10 @@ class BackupJob < ::ApplicationJob
end
end
+ def remove_backup_attachment!
+ backup.attachments.each(&:destroy)
+ end
+
def store_backup(file_name, backup:, user:)
File.open(file_name) do |file|
call = Attachments::CreateService
@@ -228,18 +243,6 @@ class BackupJob < ::ApplicationJob
"pg_dump -x -O -f '#{output_file_path}'"
end
- def success!
- payload = download_payload(url_helpers.backups_path(target_project))
-
- if errors.any?
- payload[:errors] = errors
- end
-
- upsert_status status: :success,
- message: I18n.t('copy_project.succeeded', target_project_name: target_project.name),
- payload: payload
- end
-
def failure!(error: nil)
msg = I18n.t 'backup.failed'
diff --git a/config/locales/en.yml b/config/locales/en.yml
index bab62f53b06..705bb1bfe8c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -950,6 +950,7 @@ en:
work_package: "Work package"
backup:
+ failed: "Backup failed"
label_backup_token: "Backup token"
label_create_token: "Create backup token"
label_delete_token: "Delete backup token"