summaryrefslogtreecommitdiff
path: root/app/workers/project_export_worker.rb
blob: aaaf70f09b5c7f88fe17d5bda831ba1f98f71b4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

class ProjectExportWorker # rubocop:disable Scalability/IdempotentWorker
  include ApplicationWorker
  include ExceptionBacktrace
  include ProjectExportOptions

  feature_category :importers
  worker_resource_boundary :memory

  def perform(current_user_id, project_id, after_export_strategy = {}, params = {})
    current_user = User.find(current_user_id)
    project = Project.find(project_id)
    export_job = project.export_jobs.safe_find_or_create_by(jid: self.jid)
    after_export = build!(after_export_strategy)

    export_job&.start

    ::Projects::ImportExport::ExportService.new(project, current_user, params).execute(after_export)

    export_job&.finish
  rescue ActiveRecord::RecordNotFound, Gitlab::ImportExport::AfterExportStrategyBuilder::StrategyNotFoundError => e
    logger.error("Failed to export project #{project_id}: #{e.message}")
  end

  private

  def build!(after_export_strategy)
    strategy_klass = after_export_strategy&.delete('klass')

    Gitlab::ImportExport::AfterExportStrategyBuilder.build!(strategy_klass, after_export_strategy)
  end
end