summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-07-18 16:20:36 +0000
committerStan Hu <stanhu@gmail.com>2019-07-18 16:20:36 +0000
commit0067ea312c4ca8511e2fbec601514cfc50bacb8f (patch)
tree74dd733da773d44d70d70be2470204ac22f7ca68 /config
parent8d8c66480996124fc6e682a4130f7df00305c956 (diff)
parentf7f7c3016252a09acd68c822c8950848e313ce8a (diff)
downloadgitlab-ce-0067ea312c4ca8511e2fbec601514cfc50bacb8f.tar.gz
Merge branch 'bjk/usage_ping' into 'master'
Update usage ping cron behavior See merge request gitlab-org/gitlab-ce!30842
Diffstat (limited to 'config')
-rw-r--r--config/settings.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/config/settings.rb b/config/settings.rb
index da459afcce2..8756c120645 100644
--- a/config/settings.rb
+++ b/config/settings.rb
@@ -1,4 +1,5 @@
require 'settingslogic'
+require 'digest/md5'
# We can not use `Rails.root` here, as this file might be loaded without the
# full Rails environment being loaded. We can not use `require_relative` either,
@@ -170,14 +171,17 @@ class Settings < Settingslogic
URI.parse(url_without_path).host
end
- # Runs every minute in a random ten-minute period on Sundays, to balance the
- # load on the server receiving these pings. The usage ping is safe to run
- # multiple times because of a 24 hour exclusive lock.
+ # Runs at a random time of day on a consistent day of the week based on
+ # the instance UUID. This is to balance the load on the service receiving
+ # these pings. The sidekiq job handles temporary http failures.
def cron_for_usage_ping
hour = rand(24)
- minute = rand(6)
+ minute = rand(60)
+ # Set a default UUID for the case when the UUID hasn't been initialized.
+ uuid = Gitlab::CurrentSettings.uuid || 'uuid-not-set'
+ day_of_week = Digest::MD5.hexdigest(uuid).to_i(16) % 7
- "#{minute}0-#{minute}9 #{hour} * * 0"
+ "#{minute} #{hour} * * #{day_of_week}"
end
end
end