Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
20853049
Commit
20853049
authored
Nov 08, 2016
by
Patricio Cano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored initializer code to its own class and added tests
parent
1d3ada80
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
7 deletions
+56
-7
config/initializers/sidekiq.rb
config/initializers/sidekiq.rb
+1
-7
lib/gitlab/sidekiq_throttler.rb
lib/gitlab/sidekiq_throttler.rb
+21
-0
spec/lib/gitlab/sidekiq_throttler_spec.rb
spec/lib/gitlab/sidekiq_throttler_spec.rb
+34
-0
No files found.
config/initializers/sidekiq.rb
View file @
20853049
...
...
@@ -29,13 +29,7 @@ Sidekiq.configure_server do |config|
end
Sidekiq
::
Cron
::
Job
.
load_from_hash!
cron_jobs
if
Gitlab
::
CurrentSettings
.
sidekiq_throttling_enabled?
factor
=
current_application_settings
.
sidekiq_throttling_factor
current_application_settings
.
sidekiq_throttling_queues
.
each
do
|
queue
|
Sidekiq
::
Queue
[
queue
].
limit
=
(
factor
*
Sidekiq
.
options
[
:concurrency
]).
ceil
end
end
Gitlab
::
SidekiqThrottler
.
execute!
# Database pool should be at least `sidekiq_concurrency` + 2
# For more info, see: https://github.com/mperham/sidekiq/blob/master/4.0-Upgrade.md
...
...
lib/gitlab/sidekiq_throttler.rb
0 → 100644
View file @
20853049
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
spec/lib/gitlab/sidekiq_throttler_spec.rb
0 → 100644
View file @
20853049
require
'spec_helper'
describe
Gitlab
::
SidekiqThrottler
do
before
do
Sidekiq
.
options
[
:concurrency
]
=
35
stub_application_setting
(
sidekiq_throttling_enabled:
true
,
sidekiq_throttling_factor:
0.1
,
sidekiq_throttling_queues:
%w[build project_cache]
)
end
describe
'#set_limit'
do
it
'returns the correct limit'
do
expect
(
Gitlab
::
SidekiqThrottler
.
send
(
:set_limit
)).
to
eq
4
end
end
describe
'#execute!'
do
it
'sets limits on the selected queues'
do
Gitlab
::
SidekiqThrottler
.
execute!
expect
(
Sidekiq
::
Queue
[
'build'
].
limit
).
to
eq
4
expect
(
Sidekiq
::
Queue
[
'project_cache'
].
limit
).
to
eq
4
end
it
'does not set limits on other queues'
do
Gitlab
::
SidekiqThrottler
.
execute!
expect
(
Sidekiq
::
Queue
[
'merge'
].
limit
).
to
be_nil
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment