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
|
|
|
|
include ExceptionBacktrace
|
2020-04-08 14:13:33 +05:30
|
|
|
include ProjectExportOptions
|
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
|
2020-04-22 19:07:51 +05:30
|
|
|
urgency :throttled
|
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
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
::Projects::ImportExport::ExportService.new(project, current_user, params).execute(after_export)
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
export_job&.finish
|
|
|
|
rescue ActiveRecord::RecordNotFound, Gitlab::ImportExport::AfterExportStrategyBuilder::StrategyNotFoundError => e
|
|
|
|
logger.error("Failed to export project #{project_id}: #{e.message}")
|
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
|
|
|
|
end
|