2020-01-22 07:08:40 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
return if Rails.env.production?
|
|
|
|
|
|
|
|
namespace :gitlab do
|
|
|
|
namespace :sidekiq do
|
2020-01-24 13:09:00 -05:00
|
|
|
def write_yaml(path, banner, object)
|
2020-08-25 20:10:31 -04:00
|
|
|
File.write(path, banner + YAML.dump(object).gsub(/ *$/m, ''))
|
2020-01-24 13:09:00 -05:00
|
|
|
end
|
|
|
|
|
2020-01-22 07:08:40 -05:00
|
|
|
namespace :all_queues_yml do
|
2020-01-24 13:09:00 -05:00
|
|
|
desc 'GitLab | Sidekiq | Generate all_queues.yml based on worker definitions'
|
|
|
|
task generate: :environment do
|
2020-01-22 07:08:40 -05:00
|
|
|
banner = <<~BANNER
|
|
|
|
# This file is generated automatically by
|
|
|
|
# bin/rake gitlab:sidekiq:all_queues_yml:generate
|
|
|
|
#
|
|
|
|
# Do not edit it manually!
|
|
|
|
BANNER
|
|
|
|
|
|
|
|
foss_workers, ee_workers = Gitlab::SidekiqConfig.workers_for_all_queues_yml
|
|
|
|
|
2020-01-24 13:09:00 -05:00
|
|
|
write_yaml(Gitlab::SidekiqConfig::FOSS_QUEUE_CONFIG_PATH, banner, foss_workers)
|
2020-01-22 07:08:40 -05:00
|
|
|
|
|
|
|
if Gitlab.ee?
|
2020-01-24 13:09:00 -05:00
|
|
|
write_yaml(Gitlab::SidekiqConfig::EE_QUEUE_CONFIG_PATH, banner, ee_workers)
|
2020-01-22 07:08:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-23 01:08:32 -05:00
|
|
|
desc 'GitLab | Sidekiq | Validate that all_queues.yml matches worker definitions'
|
2020-01-22 07:08:40 -05:00
|
|
|
task check: :environment do
|
|
|
|
if Gitlab::SidekiqConfig.all_queues_yml_outdated?
|
|
|
|
raise <<~MSG
|
|
|
|
Changes in worker queues found, please update the metadata by running:
|
|
|
|
|
|
|
|
bin/rake gitlab:sidekiq:all_queues_yml:generate
|
|
|
|
|
|
|
|
Then commit and push the changes from:
|
|
|
|
|
|
|
|
- #{Gitlab::SidekiqConfig::FOSS_QUEUE_CONFIG_PATH}
|
|
|
|
- #{Gitlab::SidekiqConfig::EE_QUEUE_CONFIG_PATH}
|
|
|
|
|
|
|
|
MSG
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-24 13:09:00 -05:00
|
|
|
|
|
|
|
namespace :sidekiq_queues_yml do
|
|
|
|
desc 'GitLab | Sidekiq | Generate sidekiq_queues.yml based on worker definitions'
|
|
|
|
task generate: :environment do
|
|
|
|
banner = <<~BANNER
|
|
|
|
# This file is generated automatically by
|
|
|
|
# bin/rake gitlab:sidekiq:sidekiq_queues_yml:generate
|
|
|
|
#
|
|
|
|
# Do not edit it manually!
|
|
|
|
#
|
|
|
|
# This configuration file should be exclusively used to set queue settings for
|
|
|
|
# Sidekiq. Any other setting should be specified using the Sidekiq CLI or the
|
|
|
|
# Sidekiq Ruby API (see config/initializers/sidekiq.rb).
|
|
|
|
#
|
|
|
|
# All the queues to process and their weights. Every queue _must_ have a weight
|
|
|
|
# defined.
|
|
|
|
#
|
|
|
|
# The available weights are as follows
|
|
|
|
#
|
|
|
|
# 1: low priority
|
|
|
|
# 2: medium priority
|
|
|
|
# 3: high priority
|
|
|
|
# 5: _super_ high priority, this should only be used for _very_ important queues
|
|
|
|
#
|
|
|
|
# As per http://stackoverflow.com/a/21241357/290102 the formula for calculating
|
|
|
|
# the likelihood of a job being popped off a queue (given all queues have work
|
|
|
|
# to perform) is:
|
|
|
|
#
|
|
|
|
# chance = (queue weight / total weight of all queues) * 100
|
|
|
|
BANNER
|
|
|
|
|
|
|
|
queues_and_weights = Gitlab::SidekiqConfig.queues_for_sidekiq_queues_yml
|
|
|
|
|
|
|
|
write_yaml(Gitlab::SidekiqConfig::SIDEKIQ_QUEUES_PATH, banner, queues: queues_and_weights)
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'GitLab | Sidekiq | Validate that sidekiq_queues.yml matches worker definitions'
|
|
|
|
task check: :environment do
|
|
|
|
if Gitlab::SidekiqConfig.sidekiq_queues_yml_outdated?
|
|
|
|
raise <<~MSG
|
|
|
|
Changes in worker queues found, please update the metadata by running:
|
|
|
|
|
|
|
|
bin/rake gitlab:sidekiq:sidekiq_queues_yml:generate
|
|
|
|
|
|
|
|
Then commit and push the changes from:
|
|
|
|
|
|
|
|
- #{Gitlab::SidekiqConfig::SIDEKIQ_QUEUES_PATH}
|
|
|
|
|
|
|
|
MSG
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-22 07:08:40 -05:00
|
|
|
end
|
|
|
|
end
|