2022-03-17 21:08:35 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-03-21 09:08:30 +00:00
|
|
|
require 'httparty'
|
|
|
|
require 'csv'
|
|
|
|
|
2022-03-17 21:08:35 +00:00
|
|
|
namespace :gitlab do
|
2022-03-21 09:08:30 +00:00
|
|
|
desc "GitLab | Refresh build artifacts size project statistics for given list of Project IDs from remote CSV"
|
2022-03-17 21:08:35 +00:00
|
|
|
|
|
|
|
BUILD_ARTIFACTS_SIZE_REFRESH_ENQUEUE_BATCH_SIZE = 500
|
|
|
|
|
2022-03-21 09:08:30 +00:00
|
|
|
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
|
2022-03-17 21:08:35 +00:00
|
|
|
|
|
|
|
if project_ids.any?
|
2022-03-21 09:08:30 +00:00
|
|
|
project_ids.in_groups_of(BUILD_ARTIFACTS_SIZE_REFRESH_ENQUEUE_BATCH_SIZE, false) do |ids|
|
2022-03-17 21:08:35 +00:00
|
|
|
projects = Project.where(id: ids)
|
|
|
|
Projects::BuildArtifactsSizeRefresh.enqueue_refresh(projects)
|
2022-03-21 09:08:30 +00:00
|
|
|
|
|
|
|
imported += projects.size
|
|
|
|
missing += ids.size - projects.size
|
|
|
|
puts "#{imported}/#{project_ids.size} (missing projects: #{missing})"
|
2022-03-17 21:08:35 +00:00
|
|
|
end
|
|
|
|
puts 'Done.'.green
|
|
|
|
else
|
2022-03-21 09:08:30 +00:00
|
|
|
puts 'Project IDs must be listed in the CSV under the header PROJECT_ID'.red
|
2022-03-17 21:08:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|