Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_relation_exports_worker.rb « import_export « projects « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ca69a5500a9e87cc0ff2b63079f647e57532ec8 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

module Projects
  module ImportExport
    class CreateRelationExportsWorker
      include ApplicationWorker
      include ExceptionBacktrace

      idempotent!
      data_consistency :always
      deduplicate :until_executed
      feature_category :importers
      worker_resource_boundary :cpu
      sidekiq_options status_expiration: StuckExportJobsWorker::EXPORT_JOBS_EXPIRATION

      # This delay is an arbitrary number to finish the export quicker in case all relations
      # are exported before the first execution of the WaitRelationExportsWorker worker.
      INITIAL_DELAY = 10.seconds

      # rubocop: disable CodeReuse/ActiveRecord
      def perform(user_id, project_id, after_export_strategy = {})
        project = Project.find_by_id(project_id)
        return unless project

        project_export_job = project.export_jobs.find_or_create_by!(jid: jid)
        return if project_export_job.started?

        relation_exports = RelationExport.relation_names_list.map do |relation_name|
          project_export_job.relation_exports.find_or_create_by!(relation: relation_name)
        end

        relation_exports.each do |relation_export|
          RelationExportWorker.with_status.perform_async(relation_export.id)
        end

        WaitRelationExportsWorker.perform_in(
          INITIAL_DELAY,
          project_export_job.id,
          user_id,
          after_export_strategy
        )

        project_export_job.start!
      end
      # rubocop: enable CodeReuse/ActiveRecord
    end
  end
end