debian-mirror-gitlab/app/workers/project_export_worker.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.9 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2020-04-08 14:13:33 +05:30
class ProjectExportWorker # rubocop:disable Scalability/IdempotentWorker
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2021-10-27 15:23:28 +05:30
data_consistency :always
2018-03-17 18:26:18 +05:30
include ExceptionBacktrace
2016-06-22 15:30:34 +05:30
2020-03-13 15:44:24 +05:30
feature_category :importers
2019-12-26 22:10:19 +05:30
worker_resource_boundary :memory
2022-06-21 17:19:12 +05:30
urgency :low
2020-06-23 00:09:42 +05:30
loggable_arguments 2, 3
2021-01-03 14:25:43 +05:30
sidekiq_options retry: false, dead: false
2020-07-28 23:09:34 +05:30
sidekiq_options status_expiration: StuckExportJobsWorker::EXPORT_JOBS_EXPIRATION
2016-06-22 15:30:34 +05:30
2018-05-09 12:01:36 +05:30
def perform(current_user_id, project_id, after_export_strategy = {}, params = {})
2016-06-22 15:30:34 +05:30
current_user = User.find(current_user_id)
project = Project.find(project_id)
2020-04-08 14:13:33 +05:30
export_job = project.export_jobs.safe_find_or_create_by(jid: self.jid)
2018-05-09 12:01:36 +05:30
after_export = build!(after_export_strategy)
2016-06-22 15:30:34 +05:30
2020-04-08 14:13:33 +05:30
export_job&.start
2022-06-21 17:19:12 +05:30
export_service = ::Projects::ImportExport::ExportService.new(project, current_user, params)
export_service.execute(after_export)
log_exporters_duration(export_service)
2020-04-08 14:13:33 +05:30
export_job&.finish
2022-04-04 11:22:00 +05:30
rescue ActiveRecord::RecordNotFound => e
log_failure(project_id, e)
rescue Gitlab::ImportExport::AfterExportStrategyBuilder::StrategyNotFoundError => e
log_failure(project_id, e)
export_job&.finish
rescue StandardError => e
log_failure(project_id, e)
export_job&.fail_op
raise
2018-05-09 12:01:36 +05:30
end
private
def build!(after_export_strategy)
strategy_klass = after_export_strategy&.delete('klass')
Gitlab::ImportExport::AfterExportStrategyBuilder.build!(strategy_klass, after_export_strategy)
2016-06-22 15:30:34 +05:30
end
2022-04-04 11:22:00 +05:30
def log_failure(project_id, ex)
logger.error("Failed to export project #{project_id}: #{ex.message}")
end
2022-06-21 17:19:12 +05:30
def log_exporters_duration(export_service)
export_service.exporters.each do |exporter|
exporter_key = "#{exporter.class.name.demodulize.underscore}_duration_s".to_sym # e.g. uploads_saver_duration_s
exporter_duration = exporter.duration_s&.round(6)
log_extra_metadata_on_done(exporter_key, exporter_duration)
end
end
2016-06-22 15:30:34 +05:30
end