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

refresh_project_statistics_build_artifacts_size.rake « gitlab « tasks « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 203d500b616c5c043745304aef51c66067480457 (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
# frozen_string_literal: true

require 'httparty'
require 'csv'

namespace :gitlab do
  desc "GitLab | Refresh build artifacts size project statistics for given list of Project IDs from remote CSV"

  BUILD_ARTIFACTS_SIZE_REFRESH_ENQUEUE_BATCH_SIZE = 500

  task :refresh_project_statistics_build_artifacts_size, [:csv_url] => :environment do |_t, args|
    csv_url = args.csv_url

    # rubocop: disable Gitlab/HTTParty
    body = HTTParty.get(csv_url)
    # rubocop: enable Gitlab/HTTParty

    table = CSV.parse(body.to_s, headers: true)
    project_ids = table['PROJECT_ID']

    puts "Loaded #{project_ids.size} project ids to import"

    imported = 0
    missing = 0

    if project_ids.any?
      project_ids.in_groups_of(BUILD_ARTIFACTS_SIZE_REFRESH_ENQUEUE_BATCH_SIZE, false) do |ids|
        projects = Project.where(id: ids)
        Projects::BuildArtifactsSizeRefresh.enqueue_refresh(projects)

        # Take a short break to allow replication to catch up
        Kernel.sleep(1)

        imported += projects.size
        missing += ids.size - projects.size
        puts "#{imported}/#{project_ids.size} (missing projects: #{missing})"
      end
      puts 'Done.'
    else
      puts 'Project IDs must be listed in the CSV under the header PROJECT_ID'.red
    end
  end
end