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