diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-11-09 01:31:37 +0300 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-11-10 20:38:11 +0300 |
commit | 208530494e5d2c5c62a3e1c24489aae0e4935e3a (patch) | |
tree | 5e4d76a6380566ab771b58c5017fba23ff321ace /lib/gitlab/sidekiq_throttler.rb | |
parent | 1d3ada80ad6cb9a4927512fdf4018907bf3098a6 (diff) |
Refactored initializer code to its own class and added tests
Diffstat (limited to 'lib/gitlab/sidekiq_throttler.rb')
-rw-r--r-- | lib/gitlab/sidekiq_throttler.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/gitlab/sidekiq_throttler.rb b/lib/gitlab/sidekiq_throttler.rb new file mode 100644 index 00000000000..771736e7606 --- /dev/null +++ b/lib/gitlab/sidekiq_throttler.rb @@ -0,0 +1,21 @@ +module Gitlab + class SidekiqThrottler + class << self + def execute! + if Gitlab::CurrentSettings.sidekiq_throttling_enabled? + current_application_settings.sidekiq_throttling_queues.each do |queue| + Sidekiq::Queue[queue].limit = set_limit + end + end + end + + private + + def set_limit + factor = current_application_settings.sidekiq_throttling_factor + + (factor * Sidekiq.options[:concurrency]).ceil + end + end + end +end |