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
|
2017-08-24 15:24:58 -04:00
|
|
|
include ExceptionBacktrace
|
2020-03-12 05:09:55 -04:00
|
|
|
include ProjectExportOptions
|
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
|
2020-03-25 11:07:47 -04:00
|
|
|
urgency :throttled
|
2016-05-04 04:59:33 -04:00
|
|
|
|
2020-04-30 11:09:46 -04:00
|
|
|
def perform(current_user_id, project_id, after_export_strategy = {}, params = {}, options = {})
|
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
|
|
|
|
|
2020-04-30 11:09:46 -04:00
|
|
|
::Projects::ImportExport::ExportService.new(project, current_user, params).execute(after_export, options)
|
2020-03-12 05:09:55 -04:00
|
|
|
|
|
|
|
export_job&.finish
|
|
|
|
rescue ActiveRecord::RecordNotFound, Gitlab::ImportExport::AfterExportStrategyBuilder::StrategyNotFoundError => e
|
|
|
|
logger.error("Failed to export project #{project_id}: #{e.message}")
|
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
|
|
|
|
end
|