2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-19 13:09:10 -05:00
|
|
|
class ProjectExportWorker # rubocop:disable Scalability/IdempotentWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2021-07-21 08:09:35 -04:00
|
|
|
|
|
|
|
data_consistency :always
|
2017-08-24 15:24:58 -04:00
|
|
|
include ExceptionBacktrace
|
2016-05-04 04:59:33 -04:00
|
|
|
|
2020-02-12 13:09:21 -05:00
|
|
|
feature_category :importers
|
2019-10-30 11:14:17 -04:00
|
|
|
worker_resource_boundary :memory
|
2022-03-30 11:09:00 -04:00
|
|
|
urgency :low
|
2020-06-12 08:08:56 -04:00
|
|
|
loggable_arguments 2, 3
|
2020-10-15 23:08:29 -04:00
|
|
|
sidekiq_options retry: false, dead: false
|
2020-07-01 11:08:45 -04:00
|
|
|
sidekiq_options status_expiration: StuckExportJobsWorker::EXPORT_JOBS_EXPIRATION
|
2016-05-04 04:59:33 -04:00
|
|
|
|
2020-05-13 08:07:54 -04:00
|
|
|
def perform(current_user_id, project_id, after_export_strategy = {}, params = {})
|
2016-05-04 04:59:33 -04:00
|
|
|
current_user = User.find(current_user_id)
|
|
|
|
project = Project.find(project_id)
|
2020-03-12 05:09:55 -04:00
|
|
|
export_job = project.export_jobs.safe_find_or_create_by(jid: self.jid)
|
2018-03-30 11:45:59 -04:00
|
|
|
after_export = build!(after_export_strategy)
|
2016-06-14 10:31:03 -04:00
|
|
|
|
2020-03-12 05:09:55 -04:00
|
|
|
export_job&.start
|
|
|
|
|
2022-04-06 11:08:23 -04:00
|
|
|
export_service = ::Projects::ImportExport::ExportService.new(project, current_user, params)
|
|
|
|
export_service.execute(after_export)
|
|
|
|
|
|
|
|
log_exporters_duration(export_service)
|
2020-03-12 05:09:55 -04:00
|
|
|
|
|
|
|
export_job&.finish
|
2022-01-27 10:14:51 -05:00
|
|
|
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-03-30 11:45:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def build!(after_export_strategy)
|
|
|
|
strategy_klass = after_export_strategy&.delete('klass')
|
|
|
|
|
|
|
|
Gitlab::ImportExport::AfterExportStrategyBuilder.build!(strategy_klass, after_export_strategy)
|
2016-05-04 04:59:33 -04:00
|
|
|
end
|
2022-01-27 10:14:51 -05:00
|
|
|
|
|
|
|
def log_failure(project_id, ex)
|
|
|
|
logger.error("Failed to export project #{project_id}: #{ex.message}")
|
|
|
|
end
|
2022-04-06 11:08:23 -04:00
|
|
|
|
|
|
|
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-05-04 04:59:33 -04:00
|
|
|
end
|