Class: Gitlab::BitbucketServerImport::Importers::PullRequestsImporter

Inherits:
Object
  • Object
show all
Includes:
ParallelScheduling
Defined in:
lib/gitlab/bitbucket_server_import/importers/pull_requests_importer.rb

Constant Summary

Constants included from ParallelScheduling

ParallelScheduling::ALREADY_PROCESSED_CACHE_KEY, ParallelScheduling::BATCH_SIZE, ParallelScheduling::JOB_WAITER_CACHE_KEY

Instance Attribute Summary

Attributes included from ParallelScheduling

#already_processed_cache_key, #job_waiter_cache_key, #project

Instance Method Summary collapse

Methods included from ParallelScheduling

#initialize

Methods included from Loggable

#log_debug, #log_error, #log_info, #log_warn

Instance Method Details

#executeObject



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
# File 'lib/gitlab/bitbucket_server_import/importers/pull_requests_importer.rb', line 9

def execute
  page = 1

  loop do
    log_info(
      import_stage: 'import_pull_requests', message: "importing page #{page} using batch-size #{BATCH_SIZE}"
    )

    pull_requests = client.pull_requests(
      project_key, repository_slug, page_offset: page, limit: BATCH_SIZE
    ).to_a

    break if pull_requests.empty?

    pull_requests.each do |pull_request|
      # Needs to come before `already_processed?` as `jobs_remaining` resets to zero when the job restarts and
      # jobs_remaining needs to be the total amount of enqueued jobs
      job_waiter.jobs_remaining += 1

      next if already_processed?(pull_request)

      job_delay = calculate_job_delay(job_waiter.jobs_remaining)

      sidekiq_worker_class.perform_in(job_delay, project.id, pull_request.to_hash, job_waiter.key)

      mark_as_processed(pull_request)
    end

    page += 1
  end

  job_waiter
end