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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
d48249b2
Commit
d48249b2
authored
Mar 21, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Backoff strategy to a concern
parent
b9d3f9a9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
35 deletions
+32
-35
app/workers/concerns/geo_dynamic_backoff.rb
app/workers/concerns/geo_dynamic_backoff.rb
+26
-0
app/workers/geo_key_change_notify_worker.rb
app/workers/geo_key_change_notify_worker.rb
+2
-17
app/workers/geo_key_refresh_worker.rb
app/workers/geo_key_refresh_worker.rb
+2
-17
config/application.rb
config/application.rb
+2
-1
No files found.
app/workers/concerns/geo_dynamic_backoff.rb
0 → 100644
View file @
d48249b2
require
'active_support/concern'
module
GeoDynamicBackoff
extend
ActiveSupport
::
Concern
included
do
sidekiq_options
retry:
55
sidekiq_retry_in
do
|
count
|
count
<=
30
?
linear_backoff_strategy
(
count
)
:
geometric_backoff_strategy
(
count
)
end
end
private
def
linear_backoff_strategy
(
count
)
rand
(
1
..
20
)
+
count
end
def
geometric_backoff_strategy
(
count
)
# This strategy is based on the original one from sidekiq
count
=
count
-
30
# we must start counting after 30
(
count
**
4
)
+
15
+
(
rand
(
30
)
*
(
count
+
1
))
end
end
app/workers/geo_key_change_notify_worker.rb
View file @
d48249b2
class
GeoKeyChangeNotifyWorker
include
Sidekiq
::
Worker
include
GeoDynamicBackoff
sidekiq_options
queue: :default
,
retry:
55
sidekiq_retry_in
do
|
count
|
count
<=
30
?
linear_backoff_strategy
(
count
)
:
geometric_backoff_strategy
(
count
)
end
sidekiq_options
queue: :default
def
perform
(
key_id
,
key
,
action
)
Geo
::
NotifyKeyChangeService
.
new
(
key_id
,
key
,
action
).
execute
end
private
def
linear_backoff_strategy
(
count
)
rand
(
1
..
20
)
+
count
end
def
geometric_backoff_strategy
(
count
)
# This strategy is based on the original one from sidekiq
count
=
count
-
30
# we must start counting after 30
(
count
**
4
)
+
15
+
(
rand
(
30
)
*
(
count
+
1
))
end
end
app/workers/geo_key_refresh_worker.rb
View file @
d48249b2
class
GeoKeyRefreshWorker
include
Sidekiq
::
Worker
include
GeoDynamicBackoff
sidekiq_options
queue: :default
,
retry:
55
sidekiq_retry_in
do
|
count
|
count
<=
30
?
linear_backoff_strategy
(
count
)
:
geometric_backoff_strategy
(
count
)
end
sidekiq_options
queue: :default
def
perform
(
key_id
,
key
,
action
)
action
=
action
.
to_sym
...
...
@@ -24,16 +21,4 @@ class GeoKeyRefreshWorker
fail
"Invalid action:
#{
action
}
"
end
end
private
def
linear_backoff_strategy
(
count
)
rand
(
1
..
20
)
+
count
end
def
geometric_backoff_strategy
(
count
)
# This strategy is based on the original one from sidekiq
count
=
count
-
30
# we must start counting after 30
(
count
**
4
)
+
15
+
(
rand
(
30
)
*
(
count
+
1
))
end
end
config/application.rb
View file @
d48249b2
...
...
@@ -19,7 +19,8 @@ module Gitlab
#{
config
.
root
}
/app/models/hooks
#{
config
.
root
}
/app/models/concerns
#{
config
.
root
}
/app/models/project_services
#{
config
.
root
}
/app/models/members)
)
#{
config
.
root
}
/app/models/members
#{
config
.
root
}
/app/workers/concerns)
)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
...
...
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